/**
  * This method updates the input and action maps with new ToggleAction.
  *
  * @param isToggleDynamic
  * @param isToggleLarger
  * @param key
  * @param keyStroke
  */
 private void installToggleAction(
     boolean isToggleDynamic, boolean isToggleLarger, String key, String keyStroke) {
   Action action = new ToggleAction(isToggleDynamic, isToggleLarger);
   KeyStroke ks = KeyStroke.getKeyStroke(keyStroke);
   table.getInputMap().put(ks, key);
   table.getActionMap().put(key, action);
 }
  /**
   * Luo tilikarttataulukon.
   *
   * @param container taulukon säiliö
   */
  private void createTable() {
    tableModel = new DocumentTypeTableModel();
    tableModel.setModel(model);

    table = new JTable(tableModel);
    table.setFillsViewportHeight(true);
    table.setPreferredScrollableViewportSize(new Dimension(400, 250));
    table.setRowHeight(24);

    TableColumn column;
    int[] widths = new int[] {80, 140, 80, 80};

    for (int i = 0; i < widths.length; i++) {
      column = table.getColumnModel().getColumn(i);
      column.setPreferredWidth(widths[i]);
    }

    /* Muutetaan enter-näppäimen toiminta. */
    table
        .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "nextCell");

    table.getActionMap().put("nextCell", nextCellAction);

    add(
        new JScrollPane(
            table,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER),
        BorderLayout.CENTER);
  }
Exemple #3
0
 private static JTable createUITable(
     boolean keyColumnResizable, int typeWidth, Type type, List<String> lst, Actions editAction) {
   String[] keys = lst.toArray(new String[lst.size()]);
   Arrays.sort(keys);
   TableModel mdl = type == null ? new UITableModel(keys) : new UITypeTableModel(keys, type, true);
   JTable table = new UITable(mdl, null);
   table.putClientProperty("JTable.autoStartsEdit", Boolean.FALSE);
   table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
   table.setRowHeight(25);
   TableColumnModel columns = table.getColumnModel();
   int keyWidth = TABLE_WIDTH - typeWidth - VALUE_WIDTH - DEFAULT_WIDTH;
   columns.getColumn(UITableModel.KEY_COLUMN_INDEX).setMinWidth(keyWidth);
   columns.getColumn(UITableModel.KEY_COLUMN_INDEX).setPreferredWidth(keyWidth);
   columns.getColumn(UITableModel.KEY_COLUMN_INDEX).setResizable(keyColumnResizable);
   Creator.setWidth(columns.getColumn(UITableModel.TYPE_COLUMN_INDEX), typeWidth);
   TableColumn column = columns.getColumn(UITableModel.VALUE_COLUMN_INDEX);
   Creator.setWidth(column, VALUE_WIDTH);
   column.setCellRenderer(new UIDefaultsRenderer());
   column.setCellEditor(new UIDefaultsEditor());
   Creator.setWidth(columns.getColumn(UITableModel.DEFAULT_COLUMN_INDEX), DEFAULT_WIDTH);
   table.setAutoCreateRowSorter(true);
   DefaultRowSorter<?, ?> sorter = (DefaultRowSorter<?, ?>) table.getRowSorter();
   sorter.setSortable(UITableModel.VALUE_COLUMN_INDEX, false);
   table
       .getInputMap(JComponent.WHEN_FOCUSED)
       .put(KeyStroke.getKeyStroke(KeyEvent.VK_CONTEXT_MENU, 0), editAction);
   table.getActionMap().put(editAction, editAction);
   return table;
 }
 /**
  * This method updates the input and action maps with a new ColumnAction.
  *
  * @param isSelectedColumn
  * @param isAdjust
  * @param key
  * @param keyStroke
  */
 private void installColumnAction(
     boolean isSelectedColumn, boolean isAdjust, String key, String keyStroke) {
   Action action = new ColumnAction(isSelectedColumn, isAdjust);
   KeyStroke ks = KeyStroke.getKeyStroke(keyStroke);
   table.getInputMap().put(ks, key);
   table.getActionMap().put(key, action);
 }
  @Override
  protected void configureTable(JTable table) {
    super.configureTable(table);

    // replace default action on enter
    table
        .getActionMap()
        .put(
            "selectNextRowCell",
            new AbstractAction() {
              @Override
              public void actionPerformed(ActionEvent ae) {}
            });
    table.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyReleased(KeyEvent ke) {
            switch (ke.getKeyCode()) {
                // press enter
              case 10:
                getOpenDialogExecutor().execute();
                break;
                // press delete
              case 127:
                deleteSelected();
                refresh();
                break;
            }
          }
        });
  }
  private JPanel createPanel() {
    table.setFillsViewportHeight(true);
    table.setFont(getMonospacedFont());

    table.addMouseListener(
        new MouseAdapter() {

          public void mouseClicked(java.awt.event.MouseEvent e) {

            if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {

              final int viewRow = table.rowAtPoint(e.getPoint());
              if (viewRow != -1) {
                final int modelRow = table.convertRowIndexToModel(viewRow);
                final Breakpoint breakPoint = tableModel.getBreakpoint(modelRow);

                disView.setViewStartingAddress(breakPoint.getAddress());
                if (sourceLevelDebugView
                    != null) { // may be NULL when debugging a plain object file without attached
                               // source
                  sourceLevelDebugView.scrollToVisible(breakPoint.getAddress());
                }
              }
            }
          };
        });

    table
        .getActionMap()
        .put(
            "deleteRow",
            new AbstractAction("deleteRow") {

              public void actionPerformed(ActionEvent e) {
                final int viewRow = table.getSelectedRow();
                final int modelRow = table.convertRowIndexToModel(viewRow);
                Breakpoint bp = tableModel.getBreakpoint(modelRow);
                emulator.deleteBreakpoint(bp);
              }
            });

    final KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0);
    table.getInputMap().put(stroke, "deleteRow");

    setColors(table);

    // setup scrollpane
    final JScrollPane pane = new JScrollPane(table);
    setColors(pane);

    // setup result panel
    final JPanel panel = new JPanel();
    setColors(panel);
    panel.setLayout(new GridBagLayout());
    final GridBagConstraints cnstrs = constraints(0, 0, true, true, GridBagConstraints.BOTH);
    panel.add(pane, cnstrs);
    return panel;
  }
Exemple #7
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);
     }
   }
 }
  // {{{ InstallPanel constructor
  InstallPanel(PluginManager window, boolean updates) {
    super(new BorderLayout(12, 12));

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    JPanel panelis = (JPanel) this.getContentPane();
    //	    panelis.setMaximumSize(new Dimension(820, 672));
    panelis.setMinimumSize(new Dimension(820, 610));
    //	    this.setLocale(java.util.Locale.getDefault());
    this.setPreferredSize(new Dimension(820, 610));
    this.setTitle("Leksikona redaktors");
    // this.setResizable(false);

    panelis.setLayout(new BorderLayout());

    vgrMod = new VardgrupuModelis(lexicon);
    vārdgrupas = new JTable(vgrMod);
    vārdgrupas.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    TableColumn column = null;
    for (int i = 0; i < vgrMod.getColumnCount(); i++) {
      column = vārdgrupas.getColumnModel().getColumn(i);
      if (i == 1) {
        column.setPreferredWidth(300); // third column is bigger
      } else {
        column.setPreferredWidth(50);
      }
    }
    vārdgrupas
        .getInputMap()
        .put(
            KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, java.awt.event.InputEvent.CTRL_DOWN_MASK),
            "deleteRow");
    vārdgrupas
        .getInputMap()
        .put(
            KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, java.awt.event.InputEvent.CTRL_DOWN_MASK),
            "insertRow");
    vārdgrupas
        .getActionMap()
        .put(
            "deleteRow",
            new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                deleteWGroup(vārdgrupas.convertRowIndexToModel(vārdgrupas.getSelectedRow()));
              }
            });
    vārdgrupas
        .getActionMap()
        .put(
            "insertRow",
            new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                insertWGroup();
              }
            });

    vārdgrupas.setBorder(BorderFactory.createLineBorder(Color.black));
    vārdgrupas
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              public void valueChanged(ListSelectionEvent e) {
                vārdgrupaSelektēta();
              }
            });

    vgrĪpMod = new AttributeModel(null);
    vgrĪpašībuTabula = new IpasibuTable(vgrĪpMod);
    vgrĪpašībuTabula.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    vgrĪpašībuTabula.setBorder(BorderFactory.createLineBorder(Color.black));
    vgrĪpašībuTabula
        .getInputMap()
        .put(
            KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, java.awt.event.InputEvent.CTRL_DOWN_MASK),
            "deleteRow");
    vgrĪpašībuTabula
        .getInputMap()
        .put(
            KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, java.awt.event.InputEvent.CTRL_DOWN_MASK),
            "insertRow");
    vgrĪpašībuTabula
        .getActionMap()
        .put(
            "deleteRow",
            new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                deleteWgroupProperty(
                    vgrĪpašībuTabula.convertRowIndexToModel(vgrĪpašībuTabula.getSelectedRow()));
              }
            });
    vgrĪpašībuTabula
        .getActionMap()
        .put(
            "insertRow",
            new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                addWgroupProperty();
              }
            });

    galMod = new EndingModel();
    galotņuTabula = new JTable(galMod);
    galotņuTabula.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    //	    galotņuTabula.setPreferredScrollableViewportSize(new Dimension(500, 70));
    galotņuTabula.setBorder(BorderFactory.createLineBorder(Color.black));
    galotņuTabula
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              public void valueChanged(ListSelectionEvent e) {
                galotneSelektēta();
              }
            });
    galotņuTabula
        .getInputMap()
        .put(
            KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, java.awt.event.InputEvent.CTRL_DOWN_MASK),
            "deleteRow");
    galotņuTabula
        .getInputMap()
        .put(
            KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, java.awt.event.InputEvent.CTRL_DOWN_MASK),
            "insertRow");
    galotņuTabula
        .getActionMap()
        .put(
            "deleteRow",
            new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                deleteEnding(galotņuTabula.convertRowIndexToModel(galotņuTabula.getSelectedRow()));
              }
            });
    galotņuTabula
        .getActionMap()
        .put(
            "insertRow",
            new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                addEnding();
              }
            });

    galĪpMod = new AttributeModel(null);
    galotņuĪpašībuTabula = new IpasibuTable(galĪpMod);
    galotņuĪpašībuTabula.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    //	    galotņuĪpašībuTabula.setPreferredScrollableViewportSize(new Dimension(500, 70));
    galotņuĪpašībuTabula.setBorder(BorderFactory.createLineBorder(Color.black));
    galotņuĪpašībuTabula
        .getInputMap()
        .put(
            KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, java.awt.event.InputEvent.CTRL_DOWN_MASK),
            "deleteRow");
    galotņuĪpašībuTabula
        .getInputMap()
        .put(
            KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, java.awt.event.InputEvent.CTRL_DOWN_MASK),
            "insertRow");
    galotņuĪpašībuTabula
        .getActionMap()
        .put(
            "deleteRow",
            new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                deleteEndingProperty(
                    galotņuĪpašībuTabula.convertRowIndexToModel(
                        galotņuĪpašībuTabula.getSelectedRow()));
              }
            });
    galotņuĪpašībuTabula
        .getActionMap()
        .put(
            "insertRow",
            new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                addEndingProperty();
              }
            });

    leksMod = new LexemeModel();

    leksēmuTabula = new JTable(leksMod);
    leksēmuTabula.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    leksēmuTabula.setBorder(BorderFactory.createLineBorder(Color.black));
    // leksēmuTabula.setAutoCreateRowSorter(true);
    leksēmuTabula
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              public void valueChanged(ListSelectionEvent e) {
                leksēmaSelektēta();
              }
            });

    leksēmuTabula
        .getInputMap()
        .put(
            KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, java.awt.event.InputEvent.CTRL_DOWN_MASK),
            "deleteRow");
    leksēmuTabula
        .getInputMap()
        .put(
            KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, java.awt.event.InputEvent.CTRL_DOWN_MASK),
            "insertRow");
    leksēmuTabula
        .getActionMap()
        .put(
            "deleteRow",
            new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                deleteLexeme(leksēmuTabula.convertRowIndexToModel(leksēmuTabula.getSelectedRow()));
              }
            });
    leksēmuTabula
        .getActionMap()
        .put(
            "insertRow",
            new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                addLexeme();
              }
            });

    leksĪpMod = new AttributeModel(null);
    leksēmuĪpašībuTabula = new IpasibuTable(leksĪpMod);
    leksēmuĪpašībuTabula.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    leksēmuĪpašībuTabula.setBorder(BorderFactory.createLineBorder(Color.black));
    leksēmuĪpašībuTabula
        .getInputMap()
        .put(
            KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, java.awt.event.InputEvent.CTRL_DOWN_MASK),
            "deleteRow");
    leksēmuĪpašībuTabula
        .getInputMap()
        .put(
            KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, java.awt.event.InputEvent.CTRL_DOWN_MASK),
            "insertRow");
    leksēmuĪpašībuTabula
        .getActionMap()
        .put(
            "deleteRow",
            new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                deleteLexemeProperty(
                    leksēmuĪpašībuTabula.convertRowIndexToModel(
                        leksēmuĪpašībuTabula.getSelectedRow()));
              }
            });
    leksēmuĪpašībuTabula
        .getActionMap()
        .put(
            "insertRow",
            new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                addLexemeProperty();
              }
            });

    JPanel leja = new JPanel(new BorderLayout());
    JPanel pnlVgrTab = new JPanel(new BorderLayout());
    JPanel pnlVgrĪpTab = new JPanel(new BorderLayout());
    JPanel pnlGalTab = new JPanel(new BorderLayout());
    JPanel pnlGalĪpTab = new JPanel(new BorderLayout());
    JPanel pnlLeksTab = new JPanel(new BorderLayout());
    JPanel pnlLeksĪpTab = new JPanel(new BorderLayout());

    pnlVgrTab.add(lblVgr, BorderLayout.NORTH);
    pnlVgrTab.add(vārdgrupas, BorderLayout.SOUTH);
    pnlVgrTab.add(spanVgr);
    spanVgr.getViewport().add(vārdgrupas, null);

    pnlVgrĪpTab.add(lblVgrĪp, BorderLayout.NORTH);
    pnlVgrĪpTab.add(vgrĪpašībuTabula, BorderLayout.SOUTH);
    pnlVgrĪpTab.add(spanVgrĪp);
    spanVgrĪp.getViewport().add(vgrĪpašībuTabula, null);

    pnlGalTab.add(lblGal, BorderLayout.NORTH);
    pnlGalTab.add(galotņuTabula, BorderLayout.SOUTH);
    pnlGalTab.add(spanGal);
    spanGal.getViewport().add(galotņuTabula, null);

    pnlGalĪpTab.add(lblGalĪp, BorderLayout.NORTH);
    pnlGalĪpTab.add(galotņuĪpašībuTabula, BorderLayout.SOUTH);
    pnlGalĪpTab.add(spanGalĪp);
    spanGalĪp.getViewport().add(galotņuĪpašībuTabula, null);

    pnlLeksTab.add(lblLeks, BorderLayout.NORTH);
    pnlLeksTab.add(leksēmuTabula, BorderLayout.SOUTH);
    pnlLeksTab.add(spanLeks);
    spanLeks.getViewport().add(leksēmuTabula, null);

    pnlLeksĪpTab.add(lblLeksĪp, BorderLayout.NORTH);
    pnlLeksĪpTab.add(leksēmuĪpašībuTabula, BorderLayout.SOUTH);
    pnlLeksĪpTab.add(spanLeksĪp);
    spanLeksĪp.getViewport().add(leksēmuĪpašībuTabula, null);

    pnlGalTab.setPreferredSize(new Dimension(400, 400));
    pnlGalotnes.add(pnlGalTab, BorderLayout.CENTER);
    pnlGalĪpTab.setPreferredSize(new Dimension(400, 150));
    pnlGalotnes.add(pnlGalĪpTab, BorderLayout.SOUTH);

    pnlLeksTab.setPreferredSize(new Dimension(400, 400));
    pnlLeksēmas.add(pnlLeksTab, BorderLayout.CENTER);
    pnlLeksĪpTab.setPreferredSize(new Dimension(400, 150));
    pnlLeksēmas.add(pnlLeksĪpTab, BorderLayout.SOUTH);

    pnlVgrTab.setPreferredSize(new Dimension(400, 400));
    pnlKreisais.add(pnlVgrTab, BorderLayout.CENTER);
    pnlVgrĪpTab.setPreferredSize(new Dimension(400, 150));
    pnlKreisais.add(pnlVgrĪpTab, BorderLayout.SOUTH);

    centrs.add(pnlKreisais, BorderLayout.WEST);
    centrs.add(pnlLeksēmas, BorderLayout.CENTER);

    pārslēgt.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            changeTables();
          }
        });

    aizvērt.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            aizvērtLogu();
          }
        });

    leja.add(pārslēgt, BorderLayout.LINE_START);
    leja.add(aizvērt, BorderLayout.LINE_END);

    panelis.add(centrs, BorderLayout.CENTER);
    panelis.add(leja, BorderLayout.SOUTH);

    addWGroupPopupMenu();
    addWGroupPropertiesPopupMenu();
    addEndingPopupMenu();
    addEngingPropertiesPopupMenu();
    addLexemePopupMenu();
    addLexemePropertiesPopupMenu();

    this.pack();
  }
 /**
  * @param editor the editor
  * @param table where to put the action
  */
 public static void registerAction(SwingScilabVariableEditor editor, JTable table) {
   table.getActionMap().put(PRECISION, new SetPrecisionLongAction(editor, PRECISION));
   table.getInputMap().put(ScilabKeyStroke.getKeyStroke(KEY), PRECISION);
 }
Exemple #11
0
  private void init() throws Exception {
    model = new MatchTableModel();
    cbox = new JraComboBox();
    cbox.setRenderer(
        new BasicComboBoxRenderer() {
          public Component getListCellRendererComponent(
              JList l, Object val, int idx, boolean sel, boolean foc) {
            if (sel && idx >= 0 && val instanceof MatchableCollection)
              l.setToolTipText(((MatchableCollection) val).getToolTipText());
            return super.getListCellRendererComponent(l, val, idx, sel, foc);
          }
        });
    table =
        new JTable(model) {
          public void paintChildren(Graphics g) {
            super.paintChildren(g);
            paintSections(g);
          }

          public void changeSelection(int row, int col, boolean toggle, boolean extend) {
            int scrow = row;
            int oldrow = getSelectedRow();
            int oldcol = getSelectedColumn();
            int maxrow = model.getRowCount() - 2;
            if (model.isRowHeader(row) && (toggle || extend)) return;
            if (oldrow != -1 && model.isRowHeader(row)) {
              if (oldrow < row) while (row < maxrow && model.isRowHeader(++row)) ;
              else while (row > 0 && model.isRowHeader(--row)) ;
              if (model.isRowHeader(row))
                if (oldrow < row) while (row > 0 && model.isRowHeader(--row)) ;
                else while (row < maxrow && model.isRowHeader(++row)) ;
              if (model.isRowHeader(row)) row = oldrow;
            }
            if (scrow < 2) scrow = 0;
            else if (scrow <= maxrow) scrow = row;
            getSelectionModel().setSelectionInterval(row, row);
            //        super.changeSelection(row, col, false, false);
            if (oldrow < 0) oldrow = row;
            if ((toggle || extend) && (col == oldcol || row != oldrow)) {
              if (!extend) selectOrToggle(row, true);
              else {
                int beg = (oldrow > row ? row : oldrow), end = oldrow + row - beg;
                if (beg == end && extend) return;
                for (int i = beg; i <= end; i++) selectOrToggle(i, toggle);
              }
              repaint();
            }
            if (getAutoscrolls()) {
              Rectangle cellRect = getCellRect(scrow, 0, true);
              if (cellRect != null) scrollRectToVisible(cellRect);
            }
          }

          private void selectOrToggle(int row, boolean toggle) {
            if (toggle) model.toggleRowSelected(row);
            else model.setRowSelected(row, true);
          }
        };
    table.setColumnSelectionAllowed(false);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    for (int i = 0; i < model.m_columns.length; i++)
      table.getColumnModel().getColumn(i).setPreferredWidth(model.m_columns[i].m_width);
    table
        .getColumnModel()
        .getColumn(1)
        .setCellEditor(
            new DefaultCellEditor(cbox) {
              public Component getTableCellEditorComponent(
                  JTable t, Object v, boolean sel, int row, int col) {
                cbox.setModel(new DefaultComboBoxModel(model.getMatchOptions(row)));
                cbox.setToolTipText(
                    v instanceof MatchableCollection
                        ? ((MatchableCollection) v).getToolTipText()
                        : null);
                return super.getTableCellEditorComponent(t, v, sel, row, col);
              }
            });
    table.setDefaultRenderer(
        Object.class,
        new DefaultTableCellRenderer() {
          private javax.swing.border.Border emptyBorder =
              BorderFactory.createEmptyBorder(0, 2, 0, 2);
          private Color m = null;
          private Color g = Color.green.darker().darker().darker();

          private Color halfTone(Color cFrom, Color cTo, float factor) {
            return new Color(
                (int) (cFrom.getRed() * (1 - factor) + cTo.getRed() * factor),
                (int) (cFrom.getGreen() * (1 - factor) + cTo.getGreen() * factor),
                (int) (cFrom.getBlue() * (1 - factor) + cTo.getBlue() * factor));
          }

          public Component getTableCellRendererComponent(
              JTable t, Object v, boolean sel, boolean foc, int row, int col) {
            super.getTableCellRendererComponent(t, v, sel, false, row, col);
            setOpaque(true);
            setBorder(emptyBorder);
            if (model.isRowSelected(row)) {
              if (m == null) m = halfTone(Color.yellow, t.getBackground(), 0.75f);
              super.setBackground(sel ? g : m);
            } else super.setBackground(sel ? t.getSelectionBackground() : t.getBackground());
            int rc = t.convertColumnIndexToModel(col);
            if (rc == 2) setHorizontalAlignment(JLabel.TRAILING);
            else {
              setHorizontalAlignment(JLabel.LEADING);
              if (rc == 0 || rc == 1) setToolTipText(model.getToolTip(row, col));
            }
            return this;
          }
        });

    table.setRowHeight(21);
    table.setPreferredScrollableViewportSize(
        new Dimension(740, table.getPreferredScrollableViewportSize().height));
    /*    table.getActionMap().put("select-all", new AbstractAction() {
      if (e.getKeyCode() == e.VK_A && e.getModifiers() == e.CTRL_MASK) {
        for (int i = 0; i < model.getRowCount(); i++)
          model.toggleRowSelected(i);
        table.repaint();
        e.consume();
      }
    });*/

    table
        .getActionMap()
        .put(
            "selectAll",
            new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                if (table.isEditing()) table.removeEditor();
                for (int i = 0; i < model.getRowCount(); i++) model.toggleRowSelected(i);
                table.repaint();
              }
            });
    table.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == e.VK_ENTER && table.getSelectedRow() >= 0) {
              model.toggleRowSelected(table.getSelectedRow());
              table.repaint();
            }
          }
        });

    contents = new JPanel(new BorderLayout());
    okp =
        new OKpanel() {
          public void jBOK_actionPerformed() {
            OKPress();
          }

          public void jPrekid_actionPerformed() {
            CancelPress();
          }
        };
    JPanel pd = new JPanel(null);
    pd.setLayout(new BoxLayout(pd, BoxLayout.X_AXIS));

    JButton all = new JraButton();
    all.setText("Oznaèi sve");
    all.setIcon(raImages.getImageIcon(raImages.IMGALIGNJUSTIFY));
    all.setPreferredSize(new Dimension(120, 25));
    all.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            for (int i = 0; i < model.getRowCount(); i++) model.setRowSelected(i, true);
            table.repaint();
          }
        });
    okp.add(all, BorderLayout.WEST);

    contents.add(new JraScrollPane(table));
    contents.add(okp, BorderLayout.SOUTH);
    okp.registerOKPanelKeys(table);
  }
Exemple #12
0
  public ContentView(final ContentPane control) {
    super(new GridLayout(1, 1));
    this.control = control;

    data = new JTable();
    data.setModel(model = new ContentModel(getControl().getQueryModel() == null));
    data.addMouseListener(popup = new ContentPopup(this));
    data.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent key) {
            if (key.getKeyCode() == KeyEvent.VK_DOWN || key.getKeyCode() == KeyEvent.VK_PAGE_DOWN) {
              if ((ContentView.this.data.getSelectedRow()
                      == ContentView.this.data.getRowCount() - 1)
                  && !control.areAllRowsFetched()) {
                int col = ContentView.this.data.getSelectedColumn();
                int row = ContentView.this.data.getRowCount() - 1;
                ContentView.this.data.scrollRectToVisible(
                    ContentView.this.data.getCellRect(row, col, true));
                ContentView.this.data.setRowSelectionInterval(row + 1, row + 1);
                ContentView.this.data.scrollRectToVisible(
                    ContentView.this.data.getCellRect(row + 1, col, true));
                key.consume();
              }
            }
          }
        });

    JScrollPane scroll = new JScrollPane(data);
    scroll.getViewport().setBackground(UIManager.getDefaults().getColor("Table.background"));
    add(scroll);
    jsb = scroll.getVerticalScrollBar();
    jsb.addAdjustmentListener(new ListenerScrollBar());

    data.setRowSelectionAllowed(false);
    data.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    data.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    data.setDefaultRenderer(Object.class, new InternalCellRenderer());
    data.getTableHeader().addMouseListener(popup);
    data.getTableHeader().setReorderingAllowed(false);

    lines = new LineNumberView();
    lines.addMouseListener(popup);
    lines.setSelectionModel(data.getSelectionModel());
    scroll.setRowHeaderView(lines);

    JLabel cUL = new JLabel("#", JLabel.CENTER);
    cUL.setBorder(UIManager.getBorder("TableHeader.cellBorder"));
    cUL.setFont(UIManager.getFont("TableHeader.font"));
    scroll.setCorner(JScrollPane.UPPER_LEFT_CORNER, cUL);

    JLabel cLL = new JLabel();
    cLL.setBorder(new CustomLineBorder(true, false, false, false));
    scroll.setCorner(JScrollPane.LOWER_LEFT_CORNER, cLL);

    data.getColumnModel().getSelectionModel().addListSelectionListener(this);

    data.getActionMap().put("copy", ((JMenuItem) popup.getSubElementsAt(1)).getAction());
    data.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK), "copy");

    data.getActionMap().put("paste", ((JMenuItem) popup.getSubElementsAt(2)).getAction());
    data.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK), "paste");

    data.getActionMap().put("set-null", ((JMenuItem) popup.getSubElementsAt(3)).getAction());
    data.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "set-null");

    MouseAdapter ma =
        new MouseAdapter() {
          public void mousePressed(MouseEvent me) {
            ContentView.this.data.setColumnSelectionAllowed(
                me.getSource() == ContentView.this.data.getTableHeader());
            ContentView.this.data.setRowSelectionAllowed(me.getSource() == ContentView.this.lines);
          }
        };

    data.getTableHeader().addMouseListener(ma);
    data.addMouseListener(ma);
    lines.addMouseListener(ma);
  }
  /**
   * @param stylesPreferencesKey the preferences key with the list of active style sources
   *     (filenames and URLs)
   * @param iconsPreferenceKey the preference key with the list of icon sources (can be null)
   * @param availableStylesUrl the URL to the list of available style sources
   */
  public StyleSourceEditor(
      String stylesPreferencesKey, String iconsPreferenceKey, final String availableStylesUrl) {

    DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
    tblActiveStyles = new JTable(activeStylesModel = new ActiveStylesModel(selectionModel));
    tblActiveStyles.putClientProperty("terminateEditOnFocusLost", true);
    tblActiveStyles.setSelectionModel(selectionModel);
    tblActiveStyles.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    tblActiveStyles.setTableHeader(null);
    tblActiveStyles.getColumnModel().getColumn(0).setCellEditor(new FileOrUrlCellEditor());
    tblActiveStyles.setRowHeight(20);
    activeStylesModel.setActiveStyles(Main.pref.getCollection(stylesPreferencesKey, null));

    selectionModel = new DefaultListSelectionModel();
    lstAvailableStyles =
        new JList(availableStylesModel = new AvailableStylesListModel(selectionModel));
    lstAvailableStyles.setSelectionModel(selectionModel);
    lstAvailableStyles.setCellRenderer(new StyleSourceCellRenderer());
    // availableStylesModel.setStyleSources(reloadAvailableStyles(availableStylesUrl));
    this.availableStylesUrl = availableStylesUrl;

    this.pref = stylesPreferencesKey;
    this.iconpref = iconsPreferenceKey;

    JButton iconadd = null;
    JButton iconedit = null;
    JButton icondelete = null;

    if (iconsPreferenceKey != null) {
      selectionModel = new DefaultListSelectionModel();
      tblIconPaths = new JTable(iconPathsModel = new IconPathTableModel(selectionModel));
      tblIconPaths.setSelectionModel(selectionModel);
      tblIconPaths.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
      tblIconPaths.setTableHeader(null);
      tblIconPaths.getColumnModel().getColumn(0).setCellEditor(new FileOrUrlCellEditor());
      tblIconPaths.setRowHeight(20);
      iconPathsModel.setIconPaths(Main.pref.getCollection(iconsPreferenceKey, null));

      iconadd = new JButton(new NewIconPathAction());

      EditIconPathAction editIconPathAction = new EditIconPathAction();
      tblIconPaths.getSelectionModel().addListSelectionListener(editIconPathAction);
      iconedit = new JButton(editIconPathAction);

      RemoveIconPathAction removeIconPathAction = new RemoveIconPathAction();
      tblIconPaths.getSelectionModel().addListSelectionListener(removeIconPathAction);
      icondelete = new JButton(removeIconPathAction);
      tblIconPaths
          .getInputMap(JComponent.WHEN_FOCUSED)
          .put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "delete");
      tblIconPaths.getActionMap().put("delete", removeIconPathAction);
    }

    JButton add = new JButton(new NewActiveStyleAction());

    EditActiveStyleAction editActiveStyleAction = new EditActiveStyleAction();
    tblActiveStyles.getSelectionModel().addListSelectionListener(editActiveStyleAction);
    JButton edit = new JButton(editActiveStyleAction);

    RemoveActiveStylesAction removeActiveStylesAction = new RemoveActiveStylesAction();
    tblActiveStyles.getSelectionModel().addListSelectionListener(removeActiveStylesAction);
    tblActiveStyles
        .getInputMap(JComponent.WHEN_FOCUSED)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "delete");
    tblActiveStyles.getActionMap().put("delete", removeActiveStylesAction);
    JButton delete = new JButton(removeActiveStylesAction);

    ActivateStylesAction activateStylesAction = new ActivateStylesAction();
    lstAvailableStyles.addListSelectionListener(activateStylesAction);
    JButton copy = new JButton(activateStylesAction);

    JButton update = new JButton(new ReloadStylesAction(availableStylesUrl));

    setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    setLayout(new GridBagLayout());
    add(new JLabel(tr("Active styles")), GBC.eol().insets(5, 5, 5, 0));
    JScrollPane sp;
    add(sp = new JScrollPane(tblActiveStyles), GBC.eol().insets(5, 0, 5, 0).fill(GBC.BOTH));
    sp.setColumnHeaderView(null);
    JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    add(buttonPanel, GBC.eol().insets(5, 0, 5, 5).fill(GBC.HORIZONTAL));
    buttonPanel.add(add, GBC.std().insets(0, 5, 0, 0));
    buttonPanel.add(edit, GBC.std().insets(5, 5, 5, 0));
    buttonPanel.add(delete, GBC.std().insets(0, 5, 5, 0));
    buttonPanel.add(copy, GBC.std().insets(0, 5, 5, 0));
    add(
        new JLabel(tr("Available styles (from {0})", availableStylesUrl)),
        GBC.eol().insets(5, 5, 5, 0));
    add(new JScrollPane(lstAvailableStyles), GBC.eol().insets(5, 0, 5, 0).fill(GBC.BOTH));
    buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    add(buttonPanel, GBC.eol().insets(5, 0, 5, 5).fill(GBC.HORIZONTAL));
    buttonPanel.add(update, GBC.std().insets(0, 5, 0, 0));
    if (tblIconPaths != null) {
      add(new JLabel(tr("Icon paths")), GBC.eol().insets(5, -5, 5, 0));
      add(sp = new JScrollPane(tblIconPaths), GBC.eol().insets(5, 0, 5, 0).fill(GBC.BOTH));
      sp.setColumnHeaderView(null);
      buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
      add(buttonPanel, GBC.eol().insets(5, 0, 5, 5).fill(GBC.HORIZONTAL));
      buttonPanel.add(iconadd);
      buttonPanel.add(iconedit);
      buttonPanel.add(icondelete);
    }
  }
  private void init(String title) {
    diag = new JDialog(frame, title, false);

    int activePreview = Globals.prefs.getInt(JabRefPreferences.ACTIVE_PREVIEW);
    preview =
        new PreviewPanel(
            null,
            new MetaData(),
            activePreview == 0
                ? Globals.prefs.get(JabRefPreferences.PREVIEW_0)
                : Globals.prefs.get(JabRefPreferences.PREVIEW_1));

    sortedEntries =
        new SortedList<BibtexEntry>(entries, new EntryComparator(false, true, "author"));
    model = new EventTableModel<BibtexEntry>(sortedEntries, new EntryTableFormat());
    entryTable = new JTable(model);
    GeneralRenderer renderer = new GeneralRenderer(Color.white);
    entryTable.setDefaultRenderer(JLabel.class, renderer);
    entryTable.setDefaultRenderer(String.class, renderer);
    setWidths();
    TableComparatorChooser<BibtexEntry> tableSorter =
        TableComparatorChooser.install(
            entryTable, sortedEntries, AbstractTableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD);
    setupComparatorChooser(tableSorter);
    JScrollPane sp = new JScrollPane(entryTable);

    final EventSelectionModel<BibtexEntry> selectionModel =
        new EventSelectionModel<BibtexEntry>(sortedEntries);
    entryTable.setSelectionModel(selectionModel);
    selectionModel.getSelected().addListEventListener(new EntrySelectionListener());
    entryTable.addMouseListener(new TableClickListener());

    contentPane.setTopComponent(sp);
    contentPane.setBottomComponent(preview);

    // Key bindings:
    AbstractAction closeAction =
        new AbstractAction() {

          @Override
          public void actionPerformed(ActionEvent e) {
            diag.dispose();
          }
        };
    ActionMap am = contentPane.getActionMap();
    InputMap im = contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(Globals.prefs.getKey("Close dialog"), "close");
    am.put("close", closeAction);

    entryTable
        .getActionMap()
        .put(
            "copy",
            new AbstractAction() {

              @Override
              public void actionPerformed(ActionEvent e) {
                if (!selectionModel.getSelected().isEmpty()) {
                  BibtexEntry[] bes =
                      selectionModel
                          .getSelected()
                          .toArray(new BibtexEntry[selectionModel.getSelected().size()]);
                  TransferableBibtexEntry trbe = new TransferableBibtexEntry(bes);
                  // ! look at ClipBoardManager
                  Toolkit.getDefaultToolkit()
                      .getSystemClipboard()
                      .setContents(trbe, frame.basePanel());
                  frame.output(
                      Localization.lang("Copied")
                          + ' '
                          + (bes.length > 1
                              ? bes.length + " " + Localization.lang("entries")
                              : "1 " + Localization.lang("entry") + '.'));
                }
              }
            });

    diag.addWindowListener(
        new WindowAdapter() {

          @Override
          public void windowOpened(WindowEvent e) {
            contentPane.setDividerLocation(0.5f);
          }

          @Override
          public void windowClosing(WindowEvent event) {
            Globals.prefs.putInt(JabRefPreferences.SEARCH_DIALOG_WIDTH, diag.getSize().width);
            Globals.prefs.putInt(JabRefPreferences.SEARCH_DIALOG_HEIGHT, diag.getSize().height);
          }
        });

    diag.getContentPane().add(contentPane, BorderLayout.CENTER);
    // Remember and default to last size:
    diag.setSize(
        new Dimension(
            Globals.prefs.getInt(JabRefPreferences.SEARCH_DIALOG_WIDTH),
            Globals.prefs.getInt(JabRefPreferences.SEARCH_DIALOG_HEIGHT)));
    diag.setLocationRelativeTo(frame);
  }
  public MemoryPanel(final Debugger debugger, boolean is64Bit) {
    super();
    this.debugger = debugger;
    this.is64Bit = is64Bit;
    if (is64Bit) {
      addressSize = 8;
      unmappedAddrString = "??????????????????";
    } else {
      addressSize = 4;
      unmappedAddrString = "??????????";
    }
    setLayout(new BorderLayout());
    setupScrollBar();
    add(scrollBar, BorderLayout.EAST);

    model =
        new AbstractTableModel() {
          public int getRowCount() {
            return numVisibleRows;
          }

          public int getColumnCount() {
            return 2;
          }

          public Object getValueAt(int row, int column) {
            switch (column) {
              case 0:
                return bigIntToHexString(
                    startVal.add(new BigInteger(Integer.toString((row * addressSize)))));
              case 1:
                {
                  try {
                    Address addr =
                        bigIntToAddress(
                            startVal.add(new BigInteger(Integer.toString((row * addressSize)))));
                    if (addr != null) {
                      return addressToString(addr.getAddressAt(0));
                    }
                    return unmappedAddrString;
                  } catch (UnmappedAddressException e) {
                    return unmappedAddrString;
                  }
                }
              default:
                throw new RuntimeException("Column " + column + " out of bounds");
            }
          }

          public boolean isCellEditable(int row, int col) {
            return false;
          }
        };

    // View with JTable with no header
    table = new JTable(model);
    table.setTableHeader(null);
    table.setShowGrid(false);
    table.setIntercellSpacing(new Dimension(0, 0));
    table.setCellSelectionEnabled(true);
    table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    table.setDragEnabled(true);
    Font font = GraphicsUtilities.lookupFont("Courier");
    if (font == null) {
      throw new RuntimeException("Error looking up monospace font Courier");
    }
    table.setFont(font);

    // Export proper data.
    // We need to keep our own notion of the selection in order to
    // properly export data, since the selection can go beyond the
    // visible area on the screen (and since the table's model doesn't
    // back all of those slots).
    // Code thanks to Shannon.Hickey@sfbay
    table.setTransferHandler(
        new TransferHandler() {
          protected Transferable createTransferable(JComponent c) {
            JTable table = (JTable) c;
            if (haveSelection()) {
              StringBuffer buf = new StringBuffer();
              int iDir = (getRowAnchor() < getRowLead() ? 1 : -1);
              int jDir = (getColAnchor() < getColLead() ? 1 : -1);

              for (int i = getRowAnchor(); i != getRowLead() + iDir; i += iDir) {
                for (int j = getColAnchor(); j != getColLead() + jDir; j += jDir) {
                  Object val = model.getValueAt(i, j);
                  buf.append(val == null ? "" : val.toString());
                  if (j != getColLead()) {
                    buf.append("\t");
                  }
                }
                if (i != getRowLead()) {
                  buf.append("\n");
                }
              }

              return new StringTransferable(buf.toString());
            }
            return null;
          }

          public int getSourceActions(JComponent c) {
            return COPY;
          }

          public boolean importData(JComponent c, Transferable t) {
            if (canImport(c, t.getTransferDataFlavors())) {
              try {
                String str = (String) t.getTransferData(DataFlavor.stringFlavor);
                handleImport(c, str);
                return true;
              } catch (UnsupportedFlavorException ufe) {
              } catch (IOException ioe) {
              }
            }

            return false;
          }

          public boolean canImport(JComponent c, DataFlavor[] flavors) {
            for (int i = 0; i < flavors.length; i++) {
              if (DataFlavor.stringFlavor.equals(flavors[i])) {
                return true;
              }
            }
            return false;
          }

          private void handleImport(JComponent c, String str) {
            // do whatever you want with the string here
            try {
              makeVisible(debugger.parseAddress(str));
              clearSelection();
              table.clearSelection();
            } catch (NumberFormatException e) {
              System.err.println("Unable to parse address \"" + str + "\"");
            }
          }
        });

    // Supporting keyboard scrolling
    // See src/share/classes/javax/swing/plaf/metal/MetalLookAndFeel.java,
    // search for Table.AncestorInputMap

    // Actions to override:
    // selectPreviousRow, selectNextRow,
    // scrollUpChangeSelection, scrollDownChangeSelection,
    // selectPreviousRowExtendSelection, selectNextRowExtendSelection,
    // scrollDownExtendSelection, scrollUpExtendSelection (Shift-PgDn/PgUp)

    ActionMap map = table.getActionMap();

    // Up arrow
    installActionWrapper(
        map,
        "selectPreviousRow",
        new ActionWrapper() {
          public void actionPerformed(ActionEvent e) {
            beginUpdate();
            clearSelection();
            if (table.getSelectedRow() == 0) {
              scrollBar.scrollUpOrLeft();
              table.setRowSelectionInterval(0, 0);
            } else {
              super.actionPerformed(e);
            }
            maybeGrabSelection();
            endUpdate();
          }
        });
    // Down arrow
    installActionWrapper(
        map,
        "selectNextRow",
        new ActionWrapper() {
          public void actionPerformed(ActionEvent e) {
            beginUpdate();
            clearSelection();
            int row = table.getSelectedRow();
            if (row >= numUsableRows) {
              scrollBar.scrollDownOrRight();
              table.setRowSelectionInterval(row, row);
            } else {
              super.actionPerformed(e);
            }
            maybeGrabSelection();
            endUpdate();
          }
        });
    // Page up
    installActionWrapper(
        map,
        "scrollUpChangeSelection",
        new ActionWrapper() {
          public void actionPerformed(ActionEvent e) {
            beginUpdate();
            clearSelection();
            int row = table.getSelectedRow();
            scrollBar.pageUpOrLeft();
            if (row >= 0) {
              table.setRowSelectionInterval(row, row);
            }
            maybeGrabSelection();
            endUpdate();
          }
        });
    // Page down
    installActionWrapper(
        map,
        "scrollDownChangeSelection",
        new ActionWrapper() {
          public void actionPerformed(ActionEvent e) {
            beginUpdate();
            clearSelection();
            int row = table.getSelectedRow();
            scrollBar.pageDownOrRight();
            if (row >= 0) {
              table.setRowSelectionInterval(row, row);
            }
            maybeGrabSelection();
            endUpdate();
          }
        });
    // Shift + Up arrow
    installActionWrapper(
        map,
        "selectPreviousRowExtendSelection",
        new ActionWrapper() {
          public void actionPerformed(ActionEvent e) {
            beginUpdate();
            if (!haveAnchor()) {
              setAnchorFromTable();
              setLeadFromTable();
              //            setAnchor(table.getSelectedRow());
              //            setLead(table.getSelectedRow());
            }
            int newLead = getRowLead() - 1;
            int newAnchor = getRowAnchor();
            if (newLead < 0) {
              scrollBar.scrollUpOrLeft();
              ++newLead;
              ++newAnchor;
            }
            setSelection(newAnchor, newLead, getColAnchor(), getColLead());
            //          printSelection();
            endUpdate();
          }
        });
    // Shift + Left arrow
    installActionWrapper(
        map,
        "selectPreviousColumnExtendSelection",
        new ActionWrapper() {
          public void actionPerformed(ActionEvent e) {
            beginUpdate();
            if (!haveAnchor()) {
              setAnchorFromTable();
              setLeadFromTable();
            }
            int newLead = Math.max(0, getColLead() - 1);
            setSelection(getRowAnchor(), getRowLead(), getColAnchor(), newLead);
            //          printSelection();
            endUpdate();
          }
        });
    // Shift + Down arrow
    installActionWrapper(
        map,
        "selectNextRowExtendSelection",
        new ActionWrapper() {
          public void actionPerformed(ActionEvent e) {
            beginUpdate();
            if (!haveAnchor()) {
              setAnchorFromTable();
              setLeadFromTable();
              //            setAnchor(table.getSelectedRow());
              //            setLead(table.getSelectedRow());
            }
            int newLead = getRowLead() + 1;
            int newAnchor = getRowAnchor();
            if (newLead > numUsableRows) {
              scrollBar.scrollDownOrRight();
              --newLead;
              --newAnchor;
            }
            setSelection(newAnchor, newLead, getColAnchor(), getColLead());
            //          printSelection();
            endUpdate();
          }
        });
    // Shift + Right arrow
    installActionWrapper(
        map,
        "selectNextColumnExtendSelection",
        new ActionWrapper() {
          public void actionPerformed(ActionEvent e) {
            beginUpdate();
            if (!haveAnchor()) {
              setAnchorFromTable();
              setLeadFromTable();
            }
            int newLead = Math.min(model.getColumnCount() - 1, getColLead() + 1);
            setSelection(getRowAnchor(), getRowLead(), getColAnchor(), newLead);
            //          printSelection();
            endUpdate();
          }
        });
    // Shift + Page up
    installActionWrapper(
        map,
        "scrollUpExtendSelection",
        new ActionWrapper() {
          public void actionPerformed(ActionEvent e) {
            beginUpdate();
            if (!haveAnchor()) {
              setAnchorFromTable();
              setLeadFromTable();
              //            setAnchor(table.getSelectedRow());
              //            setLead(table.getSelectedRow());
            }
            int newLead = getRowLead() - numUsableRows;
            int newAnchor = getRowAnchor();
            if (newLead < 0) {
              scrollBar.pageUpOrLeft();
              newLead += numUsableRows;
              newAnchor += numUsableRows;
            }
            setSelection(newAnchor, newLead, getColAnchor(), getColLead());
            //          printSelection();
            endUpdate();
          }
        });
    // Shift + Page down
    installActionWrapper(
        map,
        "scrollDownExtendSelection",
        new ActionWrapper() {
          public void actionPerformed(ActionEvent e) {
            beginUpdate();
            if (!haveAnchor()) {
              setAnchorFromTable();
              setLeadFromTable();
              //            setAnchor(table.getSelectedRow());
              //            setLead(table.getSelectedRow());
            }
            int newLead = getRowLead() + numUsableRows;
            int newAnchor = getRowAnchor();
            if (newLead > numUsableRows) {
              scrollBar.pageDownOrRight();
              newLead -= numUsableRows;
              newAnchor -= numUsableRows;
            }
            setSelection(newAnchor, newLead, getColAnchor(), getColLead());
            //          printSelection();
            endUpdate();
          }
        });

    // Clear our notion of selection upon mouse press
    table.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            if (shouldIgnore(e)) {
              return;
            }
            // Make shift-clicking work properly
            if (e.isShiftDown()) {
              maybeGrabSelection();
              return;
            }
            //          System.err.println("  Clearing selection on mouse press");
            clearSelection();
          }
        });

    // Watch for mouse going out of bounds
    table.addMouseMotionListener(
        new MouseMotionAdapter() {
          public void mouseDragged(MouseEvent e) {
            if (shouldIgnore(e)) {
              //            System.err.println("  (Ignoring consumed mouse event)");
              return;
            }

            // Look for drag events outside table and scroll if necessary
            Point p = e.getPoint();
            if (table.rowAtPoint(p) == -1) {
              // See whether we are above or below the table
              Rectangle rect = new Rectangle();
              getBounds(rect);
              beginUpdate();
              if (p.y < rect.y) {
                //              System.err.println("  Scrolling up due to mouse event");
                // Scroll up
                scrollBar.scrollUpOrLeft();
                setSelection(getRowAnchor(), 0, getColAnchor(), getColLead());
              } else {
                //              System.err.println("  Scrolling down due to mouse event");
                // Scroll down
                scrollBar.scrollDownOrRight();
                setSelection(getRowAnchor(), numUsableRows, getColAnchor(), getColLead());
              }
              //            printSelection();
              endUpdate();
            } else {
              maybeGrabSelection();
            }
          }
        });

    add(table, BorderLayout.CENTER);

    // Make sure we recompute number of visible rows
    addComponentListener(
        new ComponentAdapter() {
          public void componentResized(ComponentEvent e) {
            recomputeNumVisibleRows();
            constrain();
          }
        });
    addHierarchyListener(
        new HierarchyListener() {
          public void hierarchyChanged(HierarchyEvent e) {
            recomputeNumVisibleRows();
            constrain();
          }
        });
    updateFromScrollBar();
  }