private void init() { agents = new JComboBox(model); agents.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { stateChanged(event); } }); agents.addActionListener(TextChangesListener.getInstance()); ctm = new CreationTableModel(); datatable = new JTable(ctm); datatable.setShowGrid(false); datatable.setEnabled(false); datatable.setTableHeader(null); datatable.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 3)); JPanel apanel = new JPanel(new BorderLayout()); apanel.add(new JLabel("Who took the photo: "), BorderLayout.WEST); apanel.add(agents, BorderLayout.CENTER); JPanel tablePanel = new JPanel(new BorderLayout()); tablePanel.add(new JScrollPane(datatable), BorderLayout.CENTER); datatable.getColumnModel().getColumn(0).setMaxWidth(120); datatable.getColumnModel().getColumn(0).setMinWidth(80); datatable.addKeyListener(TextChangesListener.getInstance()); this.add( ComponentFactory.createTitledPanel("Creator of the image:", apanel), BorderLayout.NORTH); this.add( ComponentFactory.createTitledPanel("Creation, EXIF & technical information:", tablePanel), BorderLayout.CENTER); this.add(new JSeparator(JSeparator.HORIZONTAL), BorderLayout.WEST); }
/** Creates and displays the main GUI This GUI has the list and the main * buttons */ public void showGUI() { final JScrollPane scrollPane = new JScrollPane(); table = new JTable( new DefaultTableModel( new Object[][] {}, new String[] {"Username", "Password", "Pin", "Reward"})); AccountManager.loadAccounts(); if (AccountManager.hasAccounts()) { for (Account account : AccountManager.getAccounts()) { ((DefaultTableModel) table.getModel()) .addRow( new Object[] { account.getUsername(), account.getReward(), account.getPin(), account.getReward() }); } } final JToolBar bar = new JToolBar(); bar.setMargin(new Insets(1, 1, 1, 1)); bar.setFloatable(false); removeButton = new JButton("Remove"); final JButton newButton = new JButton("Add"); final JButton doneButton = new JButton("Save"); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.getSelectionModel().addListSelectionListener(new TableSelectionListener()); table.setShowGrid(true); final TableColumnModel cm = table.getColumnModel(); cm.getColumn(cm.getColumnIndex("Password")).setCellRenderer(new PasswordCellRenderer()); cm.getColumn(cm.getColumnIndex("Password")).setCellEditor(new PasswordCellEditor()); cm.getColumn(cm.getColumnIndex("Pin")).setCellRenderer(new PasswordCellRenderer()); cm.getColumn(cm.getColumnIndex("Pin")).setCellEditor(new PasswordCellEditor()); cm.getColumn(cm.getColumnIndex("Reward")).setCellEditor(new RandomRewardEditor()); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setViewportView(table); add(scrollPane, BorderLayout.CENTER); newButton.setFocusable(false); newButton.setToolTipText(newButton.getText()); newButton.setText("+"); bar.add(newButton); removeButton.setFocusable(false); removeButton.setToolTipText(removeButton.getText()); removeButton.setText("-"); bar.add(removeButton); bar.add(Box.createHorizontalGlue()); doneButton.setToolTipText(doneButton.getText()); bar.add(doneButton); newButton.addActionListener(this); removeButton.addActionListener(this); doneButton.addActionListener(this); add(bar, BorderLayout.SOUTH); final int row = table.getSelectedRow(); removeButton.setEnabled(row >= 0 && row < table.getRowCount()); table.clearSelection(); doneButton.requestFocus(); setPreferredSize(new Dimension(600, 300)); pack(); setLocationRelativeTo(getOwner()); setResizable(false); }
public AppointmentGUI() { setDefaultCloseOperation(DISPOSE_ON_CLOSE); setBounds(100, 100, 500, 600); // window size setTitle("Appointment List"); // window title contentPane = new JPanel(); contentPane.setBorder( new EmptyBorder(3, 6, 3, 6)); // distance the plane is from the edges of the window setContentPane(contentPane); contentPane.setLayout(new BorderLayout(0, 0)); scrollPane = new JScrollPane(); contentPane.add(scrollPane, BorderLayout.CENTER); table = new JTable( new DefaultTableModel(new Object[] {"Doctor's Name", "Location", "Date", "Time"}, 60)) { public boolean isCellEditable( int row, int column) { // prevents user from editing cells; there apparently is not a cleaner // way of doing this return false; } }; table.setShowHorizontalLines(false); table.setShowVerticalLines(false); table.setShowGrid(false); table.getTableHeader().setReorderingAllowed(false); // prevent user from swapping columns table.getTableHeader().setResizingAllowed(false); // prevent user from resizing columns table.setSelectionMode( ListSelectionModel .SINGLE_INTERVAL_SELECTION); // prevent user from selecting multiple doctors table.setAutoCreateColumnsFromModel( false); // forgot why I have this here; it's probably important scrollPane.setViewportView(table); // lets table be scroll able btnPane = new JPanel(); btnPane.setLayout(new GridLayout(0, 2, 0, 0)); contentPane.add(btnPane, BorderLayout.SOUTH); btnViewAppointment = new JButton("View Appointment"); btnPane.add(btnViewAppointment); btnCancelAppointment = new JButton("Cancel Appointment"); btnPane.add(btnCancelAppointment); btnUpdateAppointment = new JButton("Update Appointment"); btnPane.add(btnUpdateAppointment); btnGoBack = new JButton("Go Back"); btnPane.add(btnGoBack); }
@NotNull private JBPopup createUsagePopup( @NotNull final List<Usage> usages, @NotNull final UsageInfoToUsageConverter.TargetElementsDescriptor descriptor, @NotNull Set<UsageNode> visibleNodes, @NotNull final FindUsagesHandler handler, final Editor editor, @NotNull final RelativePoint popupPosition, final int maxUsages, @NotNull final UsageViewImpl usageView, @NotNull final FindUsagesOptions options, @NotNull final JTable table, @NotNull final UsageViewPresentation presentation, @NotNull final AsyncProcessIcon processIcon, boolean hadMoreSeparator) { table.setRowHeight(PlatformIcons.CLASS_ICON.getIconHeight() + 2); table.setShowGrid(false); table.setShowVerticalLines(false); table.setShowHorizontalLines(false); table.setTableHeader(null); table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); table.setIntercellSpacing(new Dimension(0, 0)); PopupChooserBuilder builder = new PopupChooserBuilder(table); final String title = presentation.getTabText(); if (title != null) { String result = getFullTitle(usages, title, hadMoreSeparator, visibleNodes.size() - 1, true); builder.setTitle(result); builder.setAdText(getSecondInvocationTitle(options, handler)); } builder.setMovable(true).setResizable(true); builder.setItemChoosenCallback( new Runnable() { @Override public void run() { int[] selected = table.getSelectedRows(); for (int i : selected) { Object value = table.getValueAt(i, 0); if (value instanceof UsageNode) { Usage usage = ((UsageNode) value).getUsage(); if (usage == MORE_USAGES_SEPARATOR) { appendMoreUsages(editor, popupPosition, handler, maxUsages); return; } navigateAndHint(usage, null, handler, popupPosition, maxUsages, options); } } } }); final JBPopup[] popup = new JBPopup[1]; KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut(); if (shortcut != null) { new DumbAwareAction() { @Override public void actionPerformed(AnActionEvent e) { popup[0].cancel(); showDialogAndFindUsages(handler, popupPosition, editor, maxUsages); } }.registerCustomShortcutSet(new CustomShortcutSet(shortcut.getFirstKeyStroke()), table); } shortcut = getShowUsagesShortcut(); if (shortcut != null) { new DumbAwareAction() { @Override public void actionPerformed(AnActionEvent e) { popup[0].cancel(); searchEverywhere(options, handler, editor, popupPosition, maxUsages); } }.registerCustomShortcutSet(new CustomShortcutSet(shortcut.getFirstKeyStroke()), table); } InplaceButton settingsButton = createSettingsButton( handler, popupPosition, editor, maxUsages, new Runnable() { @Override public void run() { popup[0].cancel(); } }); ActiveComponent spinningProgress = new ActiveComponent() { @Override public void setActive(boolean active) {} @Override public JComponent getComponent() { return processIcon; } }; builder.setCommandButton(new CompositeActiveComponent(spinningProgress, settingsButton)); DefaultActionGroup toolbar = new DefaultActionGroup(); usageView.addFilteringActions(toolbar); toolbar.add(UsageGroupingRuleProviderImpl.createGroupByFileStructureAction(usageView)); toolbar.add( new AnAction( "Open Find Usages Toolwindow", "Show all usages in a separate toolwindow", AllIcons.Toolwindows.ToolWindowFind) { { AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_USAGES); setShortcutSet(action.getShortcutSet()); } @Override public void actionPerformed(AnActionEvent e) { hideHints(); popup[0].cancel(); FindUsagesManager findUsagesManager = ((FindManagerImpl) FindManager.getInstance(usageView.getProject())) .getFindUsagesManager(); findUsagesManager.findUsages( handler.getPrimaryElements(), handler.getSecondaryElements(), handler, options, FindSettings.getInstance().isSkipResultsWithOneUsage()); } }); ActionToolbar actionToolbar = ActionManager.getInstance() .createActionToolbar(ActionPlaces.USAGE_VIEW_TOOLBAR, toolbar, true); actionToolbar.setReservePlaceAutoPopupIcon(false); final JComponent toolBar = actionToolbar.getComponent(); toolBar.setOpaque(false); builder.setSettingButton(toolBar); popup[0] = builder.createPopup(); JComponent content = popup[0].getContent(); myWidth = (int) (toolBar.getPreferredSize().getWidth() + new JLabel( getFullTitle( usages, title, hadMoreSeparator, visibleNodes.size() - 1, true)) .getPreferredSize() .getWidth() + settingsButton.getPreferredSize().getWidth()); myWidth = -1; for (AnAction action : toolbar.getChildren(null)) { action.unregisterCustomShortcutSet(usageView.getComponent()); action.registerCustomShortcutSet(action.getShortcutSet(), content); } return popup[0]; }
// {{{ 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); } } // }}}
/** * Create a new, empty, not-visible TaxRef window. Really just activates the setup frame and setup * memory monitor components, then starts things off. */ public MainFrame() { setupMemoryMonitor(); // Set up the main frame. mainFrame = new JFrame(basicTitle); mainFrame.setJMenuBar(setupMenuBar()); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Set up the JTable. table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setSelectionBackground(COLOR_SELECTION_BACKGROUND); table.setShowGrid(true); // Add a blank table model so that the component renders properly on // startup. table.setModel(blankDataModel); // Add a list selection listener so we can tell the matchInfoPanel // that a new name was selected. table .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (currentCSV == null) return; int row = table.getSelectedRow(); int column = table.getSelectedColumn(); columnInfoPanel.columnChanged(column); Object o = table.getModel().getValueAt(row, column); if (Name.class.isAssignableFrom(o.getClass())) { matchInfoPanel.nameSelected(currentCSV.getRowIndex(), (Name) o, row, column); } else { matchInfoPanel.nameSelected(currentCSV.getRowIndex(), null, -1, -1); } } }); // Set up the left panel (table + matchInfoPanel) JPanel leftPanel = new JPanel(); matchInfoPanel = new MatchInformationPanel(this); leftPanel.setLayout(new BorderLayout()); leftPanel.add(matchInfoPanel, BorderLayout.SOUTH); leftPanel.add(new JScrollPane(table)); // Set up the right panel (columnInfoPanel) JPanel rightPanel = new JPanel(); columnInfoPanel = new ColumnInformationPanel(this); progressBar.setStringPainted(true); rightPanel.setLayout(new BorderLayout()); rightPanel.add(columnInfoPanel); rightPanel.add(progressBar, BorderLayout.SOUTH); // Set up a JSplitPane to split the panels up. JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, leftPanel, rightPanel); split.setResizeWeight(1); mainFrame.add(split); mainFrame.pack(); // Set up a drop target so we can pick up files mainFrame.setDropTarget( new DropTarget( mainFrame, new DropTargetAdapter() { @Override public void dragEnter(DropTargetDragEvent dtde) { // Accept any drags. dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); } @Override public void dragOver(DropTargetDragEvent dtde) {} @Override public void dropActionChanged(DropTargetDragEvent dtde) {} @Override public void dragExit(DropTargetEvent dte) {} @Override public void drop(DropTargetDropEvent dtde) { // Accept a drop as long as its File List. if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); Transferable t = dtde.getTransferable(); try { java.util.List<File> files = (java.util.List<File>) t.getTransferData(DataFlavor.javaFileListFlavor); // If we're given multiple files, pick up only the last file and load that. File f = files.get(files.size() - 1); loadFile(f, DarwinCSV.FILE_CSV_DELIMITED); } catch (UnsupportedFlavorException ex) { dtde.dropComplete(false); } catch (IOException ex) { dtde.dropComplete(false); } } } })); }
private <T extends Enum<T>> void createControls(JPanel panel, ZrtpConfigureTableModel<T> model) { ResourceManagementService resources = NeomediaActivator.getResources(); final JButton upButton = new JButton(resources.getI18NString("impl.media.configform.UP")); upButton.setOpaque(false); final JButton downButton = new JButton(resources.getI18NString("impl.media.configform.DOWN")); downButton.setOpaque(false); Container buttonBar = new TransparentPanel(new GridLayout(0, 1)); buttonBar.add(upButton); buttonBar.add(downButton); panel.setBorder(BorderFactory.createEmptyBorder(MARGIN, MARGIN, MARGIN, MARGIN)); panel.setLayout(new GridBagLayout()); final JTable table = new JTable(model.getRowCount(), 2); table.setShowGrid(false); table.setTableHeader(null); table.setModel(model); // table.setFillsViewportHeight(true); // Since 1.6 only - nicer view /* * The first column contains the check boxes which enable/disable their * associated encodings and it doesn't make sense to make it wider than * the check boxes. */ TableColumnModel tableColumnModel = table.getColumnModel(); TableColumn tableColumn = tableColumnModel.getColumn(0); tableColumn.setMaxWidth(tableColumn.getMinWidth() + 5); table.doLayout(); GridBagConstraints constraints = new GridBagConstraints(); constraints.anchor = GridBagConstraints.CENTER; constraints.fill = GridBagConstraints.BOTH; constraints.gridwidth = 1; constraints.gridx = 0; constraints.gridy = 1; constraints.weightx = 1; constraints.weighty = 1; panel.add(new JScrollPane(table), constraints); constraints.anchor = GridBagConstraints.NORTHEAST; constraints.fill = GridBagConstraints.NONE; constraints.gridwidth = 1; constraints.gridx = 1; constraints.gridy = 1; constraints.weightx = 0; constraints.weighty = 0; panel.add(buttonBar, constraints); ListSelectionListener tableSelectionListener = new ListSelectionListener() { @SuppressWarnings("unchecked") public void valueChanged(ListSelectionEvent event) { if (table.getSelectedRowCount() == 1) { int selectedRow = table.getSelectedRow(); if (selectedRow > -1) { ZrtpConfigureTableModel<T> model = (ZrtpConfigureTableModel<T>) table.getModel(); upButton.setEnabled(selectedRow > 0 && model.checkEnableUp(selectedRow)); downButton.setEnabled( selectedRow < (table.getRowCount() - 1) && model.checkEnableDown(selectedRow)); return; } } upButton.setEnabled(false); downButton.setEnabled(false); } }; table.getSelectionModel().addListSelectionListener(tableSelectionListener); TableModelListener tableListener = new TableModelListener() { @SuppressWarnings("unchecked") public void tableChanged(TableModelEvent e) { if (table.getSelectedRowCount() == 1) { int selectedRow = table.getSelectedRow(); if (selectedRow > -1) { ZrtpConfigureTableModel<T> model = (ZrtpConfigureTableModel<T>) table.getModel(); upButton.setEnabled(selectedRow > 0 && model.checkEnableUp(selectedRow)); downButton.setEnabled( selectedRow < (table.getRowCount() - 1) && model.checkEnableDown(selectedRow)); return; } } upButton.setEnabled(false); downButton.setEnabled(false); } }; table.getModel().addTableModelListener(tableListener); tableSelectionListener.valueChanged(null); ActionListener buttonListener = new ActionListener() { @SuppressWarnings("unchecked") public void actionPerformed(ActionEvent event) { Object source = event.getSource(); boolean up; if (source == upButton) up = true; else if (source == downButton) up = false; else return; int index = ((ZrtpConfigureTableModel<T>) table.getModel()) .move(table.getSelectedRow(), up, up); table.getSelectionModel().setSelectionInterval(index, index); } }; upButton.addActionListener(buttonListener); downButton.addActionListener(buttonListener); }
public JComponent createComponentImpl() { final DefaultTableModel tableModel = createModel(); myTable = new JBTable(tableModel); myTable.setIntercellSpacing(new Dimension(0, 0)); myTable.setDefaultRenderer(TableItem.class, new MyRenderer()); myTable.setShowGrid(false); myTable.setDragEnabled(false); myTable.setShowHorizontalLines(false); myTable.setShowVerticalLines(false); myTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); JPanel tablePanel = ToolbarDecorator.createDecorator(myTable) .setAddAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { FileChooserDescriptor myDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); myDescriptor.setTitle( ProjectBundle.message("add.external.annotations.path.title")); myDescriptor.setDescription( ProjectBundle.message("add.external.annotations.path.description")); VirtualFile[] files = FileChooser.chooseFiles(myDescriptor, myTable, myProject, null); final MyTableModel tableModel = (MyTableModel) myTable.getModel(); boolean changes = false; for (final VirtualFile file : files) { if (file != null) { tableModel.addTableItem(new TableItem(file)); changes = true; } } if (changes) { saveData(); TableUtil.selectRows(myTable, new int[] {tableModel.getRowCount() - 1}); } } }) .setRemoveAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { final List removedItems = TableUtil.removeSelectedItems(myTable); if (removedItems.size() > 0) { saveData(); } } }) .createPanel(); final JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(tablePanel, BorderLayout.CENTER); mainPanel.add( new JBLabel( ProjectBundle.message("project.roots.external.annotations.description"), UIUtil.ComponentStyle.SMALL, UIUtil.FontColor.BRIGHTER), BorderLayout.NORTH); return mainPanel; }
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(); }
private void initComponents() { setLayout(new BorderLayout()); final JPanel mainPanel = new TransparentPanel(); add(mainPanel, BorderLayout.NORTH); mainPanel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.anchor = GridBagConstraints.LINE_START; c.fill = GridBagConstraints.HORIZONTAL; // general encryption option enableDefaultEncryption = new SIPCommCheckBox( UtilActivator.getResources() .getI18NString("plugin.sipaccregwizz.ENABLE_DEFAULT_ENCRYPTION"), regform.isDefaultEncryption()); enableDefaultEncryption.addActionListener(this); mainPanel.add(enableDefaultEncryption, c); // warning message and button to show advanced options JLabel lblWarning = new JLabel(); lblWarning.setBorder(new EmptyBorder(10, 5, 10, 0)); lblWarning.setText( UtilActivator.getResources() .getI18NString( "plugin.sipaccregwizz.SECURITY_WARNING", new String[] { UtilActivator.getResources().getSettingsString("service.gui.APPLICATION_NAME") })); c.gridy++; mainPanel.add(lblWarning, c); cmdExpandAdvancedSettings = new JLabel(); cmdExpandAdvancedSettings.setBorder(new EmptyBorder(0, 5, 0, 0)); cmdExpandAdvancedSettings.setIcon( UtilActivator.getResources().getImage("service.gui.icons.RIGHT_ARROW_ICON")); cmdExpandAdvancedSettings.setText( UtilActivator.getResources().getI18NString("plugin.sipaccregwizz.SHOW_ADVANCED")); cmdExpandAdvancedSettings.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { cmdExpandAdvancedSettings.setIcon( UtilActivator.getResources() .getImage( pnlAdvancedSettings.isVisible() ? "service.gui.icons.RIGHT_ARROW_ICON" : "service.gui.icons.DOWN_ARROW_ICON")); pnlAdvancedSettings.setVisible(!pnlAdvancedSettings.isVisible()); pnlAdvancedSettings.revalidate(); } }); c.gridy++; mainPanel.add(cmdExpandAdvancedSettings, c); pnlAdvancedSettings = new TransparentPanel(); pnlAdvancedSettings.setLayout(new GridBagLayout()); pnlAdvancedSettings.setVisible(false); c.gridy++; mainPanel.add(pnlAdvancedSettings, c); c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.gridwidth = 2; c.gridheight = 1; c.anchor = GridBagConstraints.LINE_START; c.fill = GridBagConstraints.HORIZONTAL; pnlAdvancedSettings.add(new JSeparator(), c); // Encryption protcol preferences. JLabel lblEncryptionProtocolPreferences = new JLabel(); lblEncryptionProtocolPreferences.setText( UtilActivator.getResources() .getI18NString("plugin.sipaccregwizz.ENCRYPTION_PROTOCOL_PREFERENCES")); c.gridy++; pnlAdvancedSettings.add(lblEncryptionProtocolPreferences, c); int nbEncryptionProtocols = ENCRYPTION_PROTOCOLS.length; String[] encryptions = new String[nbEncryptionProtocols]; boolean[] selectedEncryptions = new boolean[nbEncryptionProtocols]; this.encryptionConfigurationTableModel = new EncryptionConfigurationTableModel(encryptions, selectedEncryptions); loadEncryptionProtocols(new HashMap<String, Integer>(), new HashMap<String, Boolean>()); this.encryptionProtocolPreferences = new PriorityTable(this.encryptionConfigurationTableModel, 60); this.encryptionConfigurationTableModel.addTableModelListener(this); c.gridy++; pnlAdvancedSettings.add(this.encryptionProtocolPreferences, c); // ZRTP JLabel lblZrtpOption = new JLabel(); lblZrtpOption.setBorder(new EmptyBorder(5, 5, 5, 0)); lblZrtpOption.setText( UtilActivator.getResources().getI18NString("plugin.sipaccregwizz.ZRTP_OPTION")); c.gridx = 0; c.gridy++; c.gridwidth = 1; pnlAdvancedSettings.add(lblZrtpOption, c); c.gridx = 1; pnlAdvancedSettings.add(new JSeparator(), c); enableSipZrtpAttribute = new SIPCommCheckBox( UtilActivator.getResources() .getI18NString("plugin.sipaccregwizz.ENABLE_SIPZRTP_ATTRIBUTE"), regform.isSipZrtpAttribute()); c.gridx = 0; c.gridy++; c.gridwidth = 2; pnlAdvancedSettings.add(enableSipZrtpAttribute, c); // SDES JLabel lblSDesOption = new JLabel(); lblSDesOption.setBorder(new EmptyBorder(5, 5, 5, 0)); lblSDesOption.setText( UtilActivator.getResources().getI18NString("plugin.sipaccregwizz.SDES_OPTION")); c.gridx = 0; c.gridy++; c.gridwidth = 1; pnlAdvancedSettings.add(lblSDesOption, c); c.gridx = 1; pnlAdvancedSettings.add(new JSeparator(), c); JLabel lblCipherInfo = new JLabel(); lblCipherInfo.setText( UtilActivator.getResources().getI18NString("plugin.sipaccregwizz.CIPHER_SUITES")); c.gridx = 0; c.gridy++; c.gridwidth = 2; pnlAdvancedSettings.add(lblCipherInfo, c); cipherModel = new CipherTableModel(regform.getSDesCipherSuites()); tabCiphers = new JTable(cipherModel); tabCiphers.setShowGrid(false); tabCiphers.setTableHeader(null); TableColumnModel tableColumnModel = tabCiphers.getColumnModel(); TableColumn tableColumn = tableColumnModel.getColumn(0); tableColumn.setMaxWidth(tableColumn.getMinWidth()); JScrollPane scrollPane = new JScrollPane(tabCiphers); scrollPane.setPreferredSize(new Dimension(tabCiphers.getWidth(), 100)); c.gridy++; pnlAdvancedSettings.add(scrollPane, c); // SAVP selection c.gridx = 0; c.gridwidth = 1; JLabel lblSavpOption = new JLabel(); lblSavpOption.setBorder(new EmptyBorder(5, 5, 5, 0)); lblSavpOption.setText( UtilActivator.getResources().getI18NString("plugin.sipaccregwizz.SAVP_OPTION")); if (this.displaySavpOtions) { c.gridy++; pnlAdvancedSettings.add(lblSavpOption, c); } c.gridx = 1; if (this.displaySavpOtions) { pnlAdvancedSettings.add(new JSeparator(), c); } cboSavpOption = new JComboBox(new SavpOption[] {new SavpOption(0), new SavpOption(1), new SavpOption(2)}); c.gridx = 0; c.gridwidth = 2; c.insets = new Insets(0, 20, 0, 0); if (this.displaySavpOtions) { c.gridy++; pnlAdvancedSettings.add(cboSavpOption, c); } }
public JComponent createComponentImpl() { final JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); mainPanel.setPreferredSize(new Dimension(-1, 200)); final DefaultTableModel tableModel = createModel(); myTable = new Table(tableModel); myTable.setIntercellSpacing(new Dimension(0, 0)); myTable.setDefaultRenderer(TableItem.class, new MyRenderer()); myTable.setShowGrid(false); myTable.setDragEnabled(false); myTable.setShowHorizontalLines(false); myTable.setShowVerticalLines(false); myTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); myAddPathButton = new JButton(ProjectBundle.message("module.javadoc.add.path.button")); myAddPathButton.addActionListener(new AddPathActionListener()); myRemoveButton = new JButton(ProjectBundle.message("module.javadoc.remove.button")); myRemoveButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { final List removedItems = TableUtil.removeSelectedItems(myTable); if (removedItems.size() > 0) { saveData(); } } }); final JPanel panel = new JPanel(new GridBagLayout()); panel.add( myAddPathButton, new GridBagConstraints( 0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 0), 0, 0)); panel.add( myRemoveButton, new GridBagConstraints( 0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0)); mainPanel.add(ScrollPaneFactory.createScrollPane(myTable), BorderLayout.CENTER); mainPanel.add(panel, BorderLayout.EAST); final PanelWithText panelWithText = new PanelWithText(ProjectBundle.message("project.roots.external.annotations.description")); panelWithText.setBorder(null); mainPanel.add(panelWithText, BorderLayout.NORTH); myTable .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { return; } final int selectedIndex = myTable.getSelectedRow(); myRemoveButton.setEnabled(selectedIndex >= 0); } }); if (tableModel.getRowCount() > 0) { TableUtil.selectRows(myTable, new int[] {0}); } else { myRemoveButton.setEnabled(false); } return mainPanel; }