List of usage examples for javax.swing.event ListSelectionListener ListSelectionListener
ListSelectionListener
From source file:org.interreg.docexplore.management.manage.ManageComponent.java
@SuppressWarnings("serial") public ManageComponent(MainWindow win, final ManageHandler handler, boolean editable, boolean showPages) { super(new BorderLayout()); this.win = win; this.handler = handler; this.bookList = new JList(new CollectionNode(this)); setBorder(BorderFactory.createLineBorder(Color.black, 1)); bookList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); bookList.setCellRenderer(new ManageCellRenderer()); //tree.setRowHeight(52); add(new JScrollPane(bookList), BorderLayout.CENTER); if (editable) { bookList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { int index = bookList.locationToIndex(e.getPoint()); if (index < 0 || !bookList.getCellBounds(index, index).contains(e.getPoint())) return; handler.bookOpened((Book) bookList.getModel().getElementAt(index)); }/*from ww w . j a va 2 s.co m*/ } }); this.toolbar = new ManageToolbar(this); add(toolbar, BorderLayout.NORTH); bookList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) return; int count = bookList.getSelectedIndices().length; toolbar.deleteButton.setEnabled(count > 0); toolbar.editButton.setEnabled(count == 1); // toolbar.processButton.setEnabled(count == 1); toolbar.exportButton.setEnabled(count == 1); } }); } bookList.setBackground(new JPanel().getBackground()); getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "DEL"); getActionMap().put("DEL", new AbstractAction() { public void actionPerformed(ActionEvent arg0) { @SuppressWarnings({ "unchecked", "rawtypes" }) Vector<Book> books = new Vector(Arrays.asList(bookList.getSelectedValues())); if (books.size() > 0 && handler.booksDeleted(books)) { ((CollectionNode) bookList.getModel()).reload(); bookList.clearSelection(); bookList.repaint(); } } }); }
From source file:org.interreg.docexplore.ServerConfigPanel.java
public ServerConfigPanel(final File config, final File serverDir) throws Exception { super(new LooseGridLayout(0, 1, 5, 5, true, false, SwingConstants.LEFT, SwingConstants.TOP, true, false)); this.serverDir = serverDir; this.books = new Vector<Book>(); this.bookList = new JList(new DefaultListModel()); JPanel listPanel = new JPanel(new BorderLayout()); listPanel.setBorder(BorderFactory.createTitledBorder(XMLResourceBundle.getBundledString("cfgBooksLabel"))); bookList.setOpaque(false);//from w w w. j a v a2 s . c o m bookList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); bookList.setCellRenderer(new ListCellRenderer() { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Book book = (Book) value; JLabel label = new JLabel("<html><b>" + book.name + "</b> - " + book.nPages + " pages</html>"); label.setOpaque(true); if (isSelected) { label.setBackground(TextToolbar.styleHighLightedBackground); label.setForeground(Color.white); } if (book.deleted) label.setForeground(Color.red); else if (!book.used) label.setForeground(Color.gray); return label; } }); bookList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) return; setFields((Book) bookList.getSelectedValue()); } }); JScrollPane scrollPane = new JScrollPane(bookList, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setPreferredSize(new Dimension(500, 300)); scrollPane.getVerticalScrollBar().setUnitIncrement(10); listPanel.add(scrollPane, BorderLayout.CENTER); JPanel importPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); importPanel.add(new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgImportLabel")) { public void actionPerformed(ActionEvent e) { final File inFile = DocExploreTool.getFileDialogs().openFile(DocExploreTool.getIBookCategory()); if (inFile == null) return; try { final File tmpDir = new File(serverDir, "tmp"); tmpDir.mkdir(); GuiUtils.blockUntilComplete(new ProgressRunnable() { float[] progress = { 0 }; public void run() { try { ZipUtils.unzip(inFile, tmpDir, progress); } catch (Exception ex) { ErrorHandler.defaultHandler.submit(ex); } } public float getProgress() { return (float) progress[0]; } }, ServerConfigPanel.this); File tmpFile = new File(tmpDir, "index.tmp"); ObjectInputStream input = new ObjectInputStream(new FileInputStream(tmpFile)); String bookFile = input.readUTF(); String bookName = input.readUTF(); String bookDesc = input.readUTF(); input.close(); new PresentationImporter().doImport(ServerConfigPanel.this, bookName, bookDesc, new File(tmpDir, bookFile)); FileUtils.cleanDirectory(tmpDir); FileUtils.deleteDirectory(tmpDir); updateBooks(); } catch (Exception ex) { ErrorHandler.defaultHandler.submit(ex); } } })); listPanel.add(importPanel, BorderLayout.SOUTH); add(listPanel); JPanel setupPanel = new JPanel( new LooseGridLayout(0, 1, 5, 5, true, false, SwingConstants.LEFT, SwingConstants.TOP, true, false)); setupPanel.setBorder( BorderFactory.createTitledBorder(XMLResourceBundle.getBundledString("cfgBookInfoLabel"))); usedBox = new JCheckBox(XMLResourceBundle.getBundledString("cfgUseLabel")); usedBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Book book = (Book) bookList.getSelectedValue(); if (book != null) { book.used = usedBox.isSelected(); bookList.repaint(); } } }); setupPanel.add(usedBox); JPanel fieldPanel = new JPanel(new LooseGridLayout(0, 2, 5, 5, false, false, SwingConstants.LEFT, SwingConstants.TOP, true, false)); fieldPanel.add(new JLabel(XMLResourceBundle.getBundledString("cfgTitleLabel"))); nameField = new JTextField(50); nameField.getDocument().addDocumentListener(new DocumentListener() { public void removeUpdate(DocumentEvent e) { changedUpdate(e); } public void insertUpdate(DocumentEvent e) { changedUpdate(e); } public void changedUpdate(DocumentEvent e) { Book book = (Book) bookList.getSelectedValue(); if (book == null) return; book.name = nameField.getText(); bookList.repaint(); } }); fieldPanel.add(nameField); fieldPanel.add(new JLabel(XMLResourceBundle.getBundledString("cfgDescriptionLabel"))); descField = new JTextPane(); //descField.setWrapStyleWord(true); descField.getDocument().addDocumentListener(new DocumentListener() { public void removeUpdate(DocumentEvent e) { changedUpdate(e); } public void insertUpdate(DocumentEvent e) { changedUpdate(e); } public void changedUpdate(DocumentEvent e) { Book book = (Book) bookList.getSelectedValue(); if (book == null) return; book.desc = descField.getText(); } }); scrollPane = new JScrollPane(descField, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setPreferredSize(new Dimension(420, 50)); scrollPane.getVerticalScrollBar().setUnitIncrement(10); fieldPanel.add(scrollPane); setupPanel.add(fieldPanel); exportButton = new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgExportLabel")) { public void actionPerformed(ActionEvent e) { File file = DocExploreTool.getFileDialogs().saveFile(DocExploreTool.getIBookCategory()); if (file == null) return; final Book book = (Book) bookList.getSelectedValue(); final File indexFile = new File(serverDir, "index.tmp"); try { final File outFile = file; ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(indexFile)); out.writeUTF(book.bookFile.getName()); out.writeUTF(book.name); out.writeUTF(book.desc); out.close(); GuiUtils.blockUntilComplete(new ProgressRunnable() { float[] progress = { 0 }; public void run() { try { ZipUtils.zip(serverDir, new File[] { indexFile, book.bookFile, book.bookDir }, outFile, progress, 0, 1, 9); } catch (Exception ex) { ErrorHandler.defaultHandler.submit(ex); } } public float getProgress() { return (float) progress[0]; } }, ServerConfigPanel.this); } catch (Exception ex) { ErrorHandler.defaultHandler.submit(ex); } if (indexFile.exists()) indexFile.delete(); } }); deleteButton = new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgDeleteRestoreLabel")) { public void actionPerformed(ActionEvent e) { Book book = (Book) bookList.getSelectedValue(); if (book == null) return; book.deleted = !book.deleted; bookList.repaint(); } }); JPanel actionsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); actionsPanel.add(exportButton); actionsPanel.add(deleteButton); setupPanel.add(actionsPanel); add(setupPanel); JPanel optionsPanel = new JPanel(new LooseGridLayout(0, 2, 5, 5, false, false, SwingConstants.LEFT, SwingConstants.TOP, true, false)); optionsPanel .setBorder(BorderFactory.createTitledBorder(XMLResourceBundle.getBundledString("cfgOptionsLabel"))); JPanel timeoutPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); timeoutField = new JTextField(5); timeoutPanel.add(timeoutField); timeoutPanel.add(new JLabel(XMLResourceBundle.getBundledString("cfgTimeoutLabel"))); optionsPanel.add(timeoutPanel); add(optionsPanel); updateBooks(); setFields(null); final String xml = config.exists() ? StringUtils.readFile(config) : "<config></config>"; String idle = StringUtils.getTagContent(xml, "idle"); if (idle != null) try { timeoutField.setText("" + Integer.parseInt(idle)); } catch (Throwable e) { } }
From source file:org.isatools.isacreatorconfigurator.configui.DataEntryPanel.java
private JPanel createTableListPanel() { JPanel container = new JPanel(); container.setBackground(UIHelper.BG_COLOR); container.setLayout(new BoxLayout(container, BoxLayout.PAGE_AXIS)); JLabel lab = new JLabel(tableListTitle); container.add(UIHelper.wrapComponentInPanel(lab)); container.add(Box.createVerticalStrut(5)); tableModel = new DefaultListModel(); tableList = new JList(tableModel); tableList.setCellRenderer(new TableListRenderer()); tableList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); tableList.setBackground(UIHelper.BG_COLOR); tableList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent event) { try { saveCurrentField(false, false); } catch (DataNotCompleteException dce) { showMessagePane(dce.getMessage(), JOptionPane.ERROR_MESSAGE); }//from w ww. j av a 2 s . co m MappingObject currentlyEditedTable = getCurrentlySelectedTable(); ApplicationManager.setCurrentMappingObject(currentlyEditedTable); // update the view error button visibility depending on selected tables error state. viewErrorsButton.setVisible(areThereErrorsInThisCurrentObject()); updateTableInfoDisplay(currentlyEditedTable); reformFieldList(currentlyEditedTable); } }); JScrollPane listScroller = new JScrollPane(tableList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); listScroller.getViewport().setBackground(UIHelper.BG_COLOR); listScroller.setBorder(null); listScroller.setPreferredSize(new Dimension(((int) (WIDTH * 0.25)), ((int) (HEIGHT * 0.75)))); IAppWidgetFactory.makeIAppScrollPane(listScroller); container.add(listScroller); container.add(Box.createVerticalStrut(5)); tableCountInfo = UIHelper.createLabel("", UIHelper.VER_11_PLAIN, UIHelper.DARK_GREEN_COLOR); container.add(UIHelper.wrapComponentInPanel(tableCountInfo)); container.add(Box.createVerticalStrut(5)); // create button panel to add and remove tables JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS)); buttonPanel.setBackground(UIHelper.BG_COLOR); final JLabel addTableButton = new JLabel(addTable, JLabel.LEFT); UIHelper.renderComponent(addTableButton, UIHelper.VER_12_BOLD, UIHelper.DARK_GREEN_COLOR, false); addTableButton.setOpaque(false); addTableButton.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent mouseEvent) { addTableButton.setIcon(addTableOver); } @Override public void mouseExited(MouseEvent mouseEvent) { addTableButton.setIcon(addTable); } public void mousePressed(MouseEvent event) { SwingUtilities.invokeLater(new Runnable() { public void run() { addTableButton.setIcon(addTable); applicationContainer.showJDialogAsSheet(addTableUI); } }); } }); addTableButton.setToolTipText("<html><b>Add table</b><p>Add a new table definition.</p></html>"); final JLabel removeTableButton = new JLabel(removeTable, JLabel.LEFT); UIHelper.renderComponent(removeTableButton, UIHelper.VER_12_BOLD, UIHelper.DARK_GREEN_COLOR, false); removeTableButton.setOpaque(false); removeTableButton.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent mouseEvent) { removeTableButton.setIcon(removeTableOver); } @Override public void mouseExited(MouseEvent mouseEvent) { removeTableButton.setIcon(removeTable); } public void mousePressed(MouseEvent event) { removeTableButton.setIcon(removeTable); if (tableList.getSelectedValue() != null) { String selectedTable = tableList.getSelectedValue().toString(); MappingObject toRemove = null; for (MappingObject mo : tableFields.keySet()) { if (mo.getAssayName().equals(selectedTable)) { toRemove = mo; break; } } if (toRemove != null) { tableFields.remove(toRemove); reformTableList(); } } } }); removeTableButton.setToolTipText("<html><b>Remove table</b><p>Remove table from definitions?</p></html>"); viewErrorsButton = new JLabel(viewErrorsIcon); viewErrorsButton.setVisible(false); viewErrorsButton.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent mouseEvent) { viewErrorsButton.setIcon(viewErrorsIcon); // show error pane for current table only. Validator validator = new Validator(); validateFormOrTable(validator, ApplicationManager.getCurrentMappingObject()); ValidationReport report = validator.getReport(); ConfigurationValidationUI validationUI = new ConfigurationValidationUI(tableFields.keySet(), report); validationUI.createGUI(); validationUI.setLocationRelativeTo(getApplicationContainer()); validationUI.setAlwaysOnTop(true); validationUI.setVisible(true); } @Override public void mouseEntered(MouseEvent mouseEvent) { viewErrorsButton.setIcon(viewErrorsIconOver); } @Override public void mouseExited(MouseEvent mouseEvent) { viewErrorsButton.setIcon(viewErrorsIcon); } }); buttonPanel.add(addTableButton); buttonPanel.add(removeTableButton); buttonPanel.add(viewErrorsButton); buttonPanel.add(Box.createHorizontalGlue()); container.add(buttonPanel); container.add(Box.createVerticalGlue()); return container; }
From source file:org.isatools.isacreatorconfigurator.configui.DataEntryPanel.java
private JPanel createFieldListPanel() { JPanel container = new JPanel(); container.setBackground(UIHelper.BG_COLOR); container.setLayout(new BoxLayout(container, BoxLayout.PAGE_AXIS)); JPanel headerLab = new JPanel(new GridLayout(1, 1)); headerLab.setOpaque(false);/* w ww.ja va 2s . c o m*/ JLabel lab = new JLabel(fieldListTitle); headerLab.add(lab); container.add(headerLab); container.add(Box.createVerticalStrut(5)); elementModel = new DefaultListModel(); elementList = new ReOrderableJList(elementModel); elementList.setCellRenderer(new CustomReOrderableListCellRenderer(elementList)); elementList.setDragEnabled(true); elementList.setBackground(UIHelper.BG_COLOR); elementList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent event) { Display selectedNode = (Display) elementList.getSelectedValue(); if (selectedNode != null) { try { saveCurrentField(false, false); } catch (DataNotCompleteException dce) { showMessagePane(dce.getMessage(), JOptionPane.ERROR_MESSAGE); } if (selectedNode instanceof FieldElement) { fieldInterface.setCurrentField((FieldElement) selectedNode); if (currentPage != fieldInterface) { setCurrentPage(fieldInterface); } removeElementButton.setEnabled(!standardISAFields.isFieldRequired(selectedNode.toString())); } else { setCurrentPage(structureElement); } } } }); elementList.addPropertyChangeListener("orderChanged", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent propertyChangeEvent) { updateFieldOrder(); if (tableList.getSelectedValue() instanceof MappingObject) { validateFormOrTable(ApplicationManager.getCurrentMappingObject()); } } }); JScrollPane listScroller = new JScrollPane(elementList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); listScroller.getViewport().setBackground(UIHelper.BG_COLOR); listScroller.setBorder(new EmptyBorder(2, 2, 2, 10)); listScroller.setPreferredSize(new Dimension(((int) (WIDTH * 0.25)), ((int) (HEIGHT * 0.75)))); IAppWidgetFactory.makeIAppScrollPane(listScroller); container.add(listScroller); container.add(Box.createVerticalStrut(5)); elementCountInfo = UIHelper.createLabel("", UIHelper.VER_11_PLAIN, UIHelper.DARK_GREEN_COLOR); container.add(UIHelper.wrapComponentInPanel(elementCountInfo)); container.add(Box.createVerticalStrut(5)); // create button panel to add and remove tables JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS)); buttonPanel.setBackground(UIHelper.BG_COLOR); final JLabel addFieldButton = new JLabel(addElement, JLabel.LEFT); addFieldButton.setOpaque(false); addFieldButton.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent mouseEvent) { addFieldButton.setIcon(addElementOver); } @Override public void mouseExited(MouseEvent mouseEvent) { addFieldButton.setIcon(addElement); } public void mousePressed(MouseEvent event) { addFieldButton.setIcon(addElement); showAddFieldUI(); } }); addFieldButton.setToolTipText( "<html><b>Add Field to table</b><p>Add a new field to currently selected table</b></p></html>"); removeElementButton = new JLabel(removeElement, JLabel.LEFT); removeElementButton.setOpaque(false); removeElementButton.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent mouseEvent) { removeElementButton.setIcon(removeElementOver); } @Override public void mouseExited(MouseEvent mouseEvent) { removeElementButton.setIcon(removeElement); } public void mousePressed(MouseEvent event) { removeElementButton.setIcon(removeElement); if (removeElementButton.isEnabled()) { removeSelectedElement(); } } }); removeElementButton.setToolTipText( "<html><b>Remove Field from table</b><p>Remove this field from this list and the currently selected table.</b></p></html>"); final JLabel moveDownButton = new JLabel(moveDown); moveDownButton.setOpaque(false); moveDownButton.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent mouseEvent) { moveDownButton.setIcon(moveDownOver); } @Override public void mouseExited(MouseEvent mouseEvent) { moveDownButton.setIcon(moveDown); } public void mousePressed(MouseEvent event) { moveDownButton.setIcon(moveDown); if (elementList.getSelectedIndex() != -1) { int toMoveDown = elementList.getSelectedIndex(); if (toMoveDown != (elementModel.getSize() - 1)) { swapElements(elementList, elementModel, toMoveDown, toMoveDown + 1); } updateFieldOrder(); validateFormOrTable(ApplicationManager.getCurrentMappingObject()); } } }); moveDownButton.setToolTipText( "<html><b>Move Field Down</b><p>Move the selected field down <b>one</b> position in the list.</p></html>"); final JLabel moveUpButton = new JLabel(moveUp); moveUpButton.setOpaque(false); moveUpButton.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent mouseEvent) { moveUpButton.setIcon(moveUpOver); } @Override public void mouseExited(MouseEvent mouseEvent) { moveUpButton.setIcon(moveUp); } public void mousePressed(MouseEvent event) { moveUpButton.setIcon(moveUp); if (elementList.getSelectedIndex() != -1) { int toMoveUp = elementList.getSelectedIndex(); if (toMoveUp != 0) { swapElements(elementList, elementModel, toMoveUp, toMoveUp - 1); } updateFieldOrder(); validateFormOrTable(ApplicationManager.getCurrentMappingObject()); } } }); moveUpButton.setToolTipText( "<html><b>Move Field Up</b><p>Move the selected field up <b>one</b> position in the list.</p></html>"); buttonPanel.add(addFieldButton); buttonPanel.add(removeElementButton); buttonPanel.add(moveDownButton); buttonPanel.add(moveUpButton); container.add(buttonPanel); container.add(Box.createVerticalGlue()); return container; }
From source file:org.isatools.isacreatorconfigurator.ontologyconfigurationtool.OntologyConfigUI.java
private void createOntologySelectionPanel() { OntologyListRenderer listRenderer = new OntologyListRenderer(); JPanel westPanel = new JPanel(new BorderLayout()); JPanel selectedOntologiesContainer = new JPanel(new BorderLayout()); selectedOntologiesContainer.setOpaque(false); // create List containing selected ontologies selectedOntologyListModel = new DefaultListModel(); selectedOntologyList = new JList(selectedOntologyListModel); selectedOntologyList.setCellRenderer(new SelectedOntologyListRenderer()); selectedOntologyList.setBackground(UIHelper.BG_COLOR); selectedOntologyList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent listSelectionEvent) { setOntologySelectionPanelPlaceholder(infoImage); setSelectedOntologyButtonVisibility(selectedOntologyList.isSelectionEmpty()); }/*from w w w. ja va2s. c o m*/ }); JScrollPane selectedOntologiesScroller = new JScrollPane(selectedOntologyList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); selectedOntologiesScroller.setPreferredSize(new Dimension(200, 255)); selectedOntologiesScroller.setBackground(UIHelper.BG_COLOR); selectedOntologiesScroller.getViewport().setBackground(UIHelper.BG_COLOR); IAppWidgetFactory.makeIAppScrollPane(selectedOntologiesScroller); selectedOntologiesContainer.setBorder(new TitledBorder(new RoundedBorder(UIHelper.LIGHT_GREEN_COLOR, 7), "selected ontologies", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, UIHelper.VER_11_BOLD, UIHelper.DARK_GREEN_COLOR)); selectedOntologiesContainer.add(selectedOntologiesScroller, BorderLayout.CENTER); // ADD BUTTONS removeOntologyButton = new JLabel(removeOntologyButtonIcon); removeOntologyButton.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent mouseEvent) { if (!selectedOntologyList.isSelectionEmpty()) { String ontologyToRemove = selectedOntologyList.getSelectedValue().toString(); System.out.println("Removing " + ontologyToRemove); selectedOntologies.remove(ontologyToRemove); setOntologySelectionPanelPlaceholder(infoImage); updateSelectedOntologies(); } removeOntologyButton.setIcon(removeOntologyButtonIcon); } @Override public void mouseEntered(MouseEvent mouseEvent) { removeOntologyButton.setIcon(removeOntologyButtonIconOver); } @Override public void mouseExited(MouseEvent mouseEvent) { removeOntologyButton.setIcon(removeOntologyButtonIcon); } }); removeOntologyButton.setVisible(false); viewOntologyButton = new JLabel(browseOntologyButtonIcon); viewOntologyButton.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent mouseEvent) { performTransition(); viewOntologyButton.setIcon(browseOntologyButtonIcon); } @Override public void mouseEntered(MouseEvent mouseEvent) { viewOntologyButton.setIcon(browseOntologyButtonIconOver); } @Override public void mouseExited(MouseEvent mouseEvent) { viewOntologyButton.setIcon(browseOntologyButtonIcon); } }); viewOntologyButton.setVisible(false); removeRestrictionButton = new JLabel(removeRestrictionButtonIcon); removeRestrictionButton.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent mouseEvent) { if (!selectedOntologyList.isSelectionEmpty()) { ((RecommendedOntology) selectedOntologyList.getSelectedValue()).setBranchToSearchUnder(null); removeRestrictionButton.setVisible(false); selectedOntologyList.repaint(); } removeRestrictionButton.setIcon(removeRestrictionButtonIcon); } @Override public void mouseEntered(MouseEvent mouseEvent) { removeRestrictionButton.setIcon(removeRestrictionButtonIconOver); } @Override public void mouseExited(MouseEvent mouseEvent) { removeRestrictionButton.setIcon(removeRestrictionButtonIcon); } }); removeRestrictionButton.setVisible(false); Box selectedOntologiesOptionContainer = Box.createHorizontalBox(); selectedOntologiesOptionContainer.setOpaque(false); selectedOntologiesOptionContainer.add(removeOntologyButton); selectedOntologiesOptionContainer.add(viewOntologyButton); selectedOntologiesOptionContainer.add(removeRestrictionButton); selectedOntologiesContainer.add(selectedOntologiesOptionContainer, BorderLayout.SOUTH); // create panel populated with all available ontologies inside a filterable list! JPanel availableOntologiesListContainer = new JPanel(new BorderLayout()); availableOntologiesListContainer .setBorder(new TitledBorder(new RoundedBorder(UIHelper.LIGHT_GREEN_COLOR, 7), "available ontologies", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, UIHelper.VER_11_BOLD, UIHelper.DARK_GREEN_COLOR)); final ExtendedJList availableOntologies = new ExtendedJList(listRenderer); final JLabel addOntologyButton = new JLabel(addOntologyButtonIcon); addOntologyButton.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent mouseEvent) { if (!availableOntologies.isSelectionEmpty()) { Ontology ontology = (Ontology) availableOntologies.getSelectedValue(); selectedOntologies.put(ontology.getOntologyDisplayLabel(), new RecommendedOntology(ontology)); updateSelectedOntologies(); setOntologySelectionPanelPlaceholder(infoImage); } addOntologyButton.setIcon(addOntologyButtonIcon); } @Override public void mouseEntered(MouseEvent mouseEvent) { addOntologyButton.setIcon(addOntologyButtonIconOver); } @Override public void mouseExited(MouseEvent mouseEvent) { addOntologyButton.setIcon(addOntologyButtonIcon); } }); final JLabel info = UIHelper.createLabel("", UIHelper.VER_10_PLAIN, UIHelper.DARK_GREEN_COLOR); availableOntologies.addPropertyChangeListener("update", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent propertyChangeEvent) { info.setText("<html>viewing <b>" + availableOntologies.getFilteredItems().size() + "</b> ontologies</html>"); } }); Box optionsBox = Box.createVerticalBox(); optionsBox.add(UIHelper.wrapComponentInPanel(info)); Box availableOntologiesOptionBox = Box.createHorizontalBox(); availableOntologiesOptionBox.add(addOntologyButton); availableOntologiesOptionBox.add(Box.createHorizontalGlue()); optionsBox.add(availableOntologiesOptionBox); availableOntologiesListContainer.add(optionsBox, BorderLayout.SOUTH); if (ontologiesToBrowseOn == null) { ontologiesToBrowseOn = new ArrayList<Ontology>(); List<Ontology> bioportalQueryResult = bioportalClient.getAllOntologies(); if (bioportalQueryResult != null) { ontologiesToBrowseOn.addAll(bioportalQueryResult); } ontologiesToBrowseOn.addAll(olsClient.getAllOntologies()); } // precautionary check in case of having no ontologies available to search on. if (ontologiesToBrowseOn != null) { for (Ontology o : ontologiesToBrowseOn) { availableOntologies.addItem(o); } } info.setText( "<html>viewing <b>" + availableOntologies.getFilteredItems().size() + "</b> ontologies</html>"); // need to get ontologies available from bioportal and add them here. JScrollPane availableOntologiesScroller = new JScrollPane(availableOntologies, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); availableOntologiesScroller.getViewport().setBackground(UIHelper.BG_COLOR); availableOntologiesScroller.setPreferredSize(new Dimension(200, 125)); availableOntologiesScroller.setBorder(new EmptyBorder(0, 0, 0, 0)); IAppWidgetFactory.makeIAppScrollPane(availableOntologiesScroller); availableOntologiesListContainer.add(availableOntologiesScroller); availableOntologiesListContainer.add(availableOntologies.getFilterField(), BorderLayout.NORTH); westPanel.add(selectedOntologiesContainer, BorderLayout.CENTER); westPanel.add(availableOntologiesListContainer, BorderLayout.SOUTH); add(westPanel, BorderLayout.WEST); }
From source file:org.javaswift.cloudie.CloudiePanel.java
private void createLists() { containersList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); containersList.setCellRenderer(new DefaultListCellRenderer() { @Override//from w w w . j a v a 2s . c o m public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel lbl = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); lbl.setBorder(LR_PADDING); Container c = (Container) value; lbl.setText(c.getName()); lbl.setToolTipText(lbl.getText()); return lbl; } }); containersList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { enableDisableContainerMenu(); updateStatusPanelForContainer(); } }); // storedObjectsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); storedObjectsList.setCellRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel lbl = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); lbl.setBorder(LR_PADDING); StoredObject so = (StoredObject) value; lbl.setText(so.getName()); lbl.setToolTipText(lbl.getText()); return lbl; } }); storedObjectsList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { enableDisableStoredObjectMenu(); updateStatusPanelForStoredObject(); } }); }
From source file:org.javaswift.cloudie.CloudiePanel.java
public void bind() { containersList.addListSelectionListener(new ListSelectionListener() { @Override/*w w w.j a va 2s . com*/ public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { return; } else { int idx = containersList.getSelectedIndex(); if (idx >= 0) { refreshFiles((Container) containers.get(idx)); } } } }); // Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable ex) { if (ex instanceof CommandException) { showError((CommandException) ex); } else { ex.printStackTrace(); } } }); // containersList.getInputMap().put(KeyStroke.getKeyStroke("F5"), "refresh"); containersList.getActionMap().put("refresh", containerRefreshAction); // storedObjectsList.getInputMap().put(KeyStroke.getKeyStroke("F5"), "refresh"); storedObjectsList.getActionMap().put("refresh", containerRefreshAction); // }
From source file:org.jets3t.gui.ObjectsAttributesDialog.java
/** * Initialise the GUI elements to display the given item. *///www . j a v a 2 s. com private void initGui() { this.setResizable(true); this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); JPanel unmodifiableAttributesPanel = skinsFactory.createSkinnedJPanel("ObjectStaticAttributesPanel"); unmodifiableAttributesPanel.setLayout(new GridBagLayout()); JPanel metadataContainer = skinsFactory.createSkinnedJPanel("ObjectPropertiesMetadataPanel"); metadataContainer.setLayout(new GridBagLayout()); metadataButtonsContainer = skinsFactory.createSkinnedJPanel("ObjectPropertiesMetadataButtonsPanel"); metadataButtonsContainer.setLayout(new GridBagLayout()); // Fields to display unmodifiable object details. JLabel objectKeyLabel = skinsFactory.createSkinnedJHtmlLabel("ObjectKeyLabel"); objectKeyLabel.setText("Object key:"); objectKeyTextField = skinsFactory.createSkinnedJTextField("ObjectKeyTextField"); objectKeyTextField.setEditable(false); JLabel objectContentLengthLabel = skinsFactory.createSkinnedJHtmlLabel("ObjectContentLengthLabel"); objectContentLengthLabel.setText("Size:"); objectContentLengthTextField = skinsFactory.createSkinnedJTextField("ObjectContentLengthTextField"); objectContentLengthTextField.setEditable(false); JLabel objectLastModifiedLabel = skinsFactory.createSkinnedJHtmlLabel("ObjectLastModifiedLabel"); objectLastModifiedLabel.setText("Last modified:"); objectLastModifiedTextField = skinsFactory.createSkinnedJTextField("ObjectLastModifiedTextField"); objectLastModifiedTextField.setEditable(false); JLabel objectETagLabel = skinsFactory.createSkinnedJHtmlLabel("ObjectETagLabel"); objectETagLabel.setText("ETag:"); objectETagTextField = skinsFactory.createSkinnedJTextField("ObjectETagTextField"); objectETagTextField.setEditable(false); JLabel bucketNameLabel = skinsFactory.createSkinnedJHtmlLabel("BucketNameLabel"); bucketNameLabel.setText("Bucket:"); bucketLocationTextField = skinsFactory.createSkinnedJTextField("BucketLocationTextField"); bucketLocationTextField.setEditable(false); ownerNameLabel = skinsFactory.createSkinnedJHtmlLabel("OwnerNameLabel"); ownerNameLabel.setText("Owner name:"); ownerNameTextField = skinsFactory.createSkinnedJTextField("OwnerNameTextField"); ownerNameTextField.setEditable(false); ownerIdLabel = skinsFactory.createSkinnedJHtmlLabel("OwnerIdLabel"); ownerIdLabel.setText("Owner ID:"); ownerIdTextField = skinsFactory.createSkinnedJTextField("OwnerIdTextField"); ownerIdTextField.setEditable(false); int row = 0; unmodifiableAttributesPanel.add(objectKeyLabel, new GridBagConstraints(0, row, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, insetsDefault, 0, 0)); unmodifiableAttributesPanel.add(objectKeyTextField, new GridBagConstraints(1, row, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); row++; unmodifiableAttributesPanel.add(objectContentLengthLabel, new GridBagConstraints(0, row, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, insetsDefault, 0, 0)); unmodifiableAttributesPanel.add(objectContentLengthTextField, new GridBagConstraints(1, row, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); row++; unmodifiableAttributesPanel.add(objectLastModifiedLabel, new GridBagConstraints(0, row, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, insetsDefault, 0, 0)); unmodifiableAttributesPanel.add(objectLastModifiedTextField, new GridBagConstraints(1, row, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); row++; unmodifiableAttributesPanel.add(objectETagLabel, new GridBagConstraints(0, row, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, insetsDefault, 0, 0)); unmodifiableAttributesPanel.add(objectETagTextField, new GridBagConstraints(1, row, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); row++; unmodifiableAttributesPanel.add(ownerNameLabel, new GridBagConstraints(0, row, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, insetsDefault, 0, 0)); unmodifiableAttributesPanel.add(ownerNameTextField, new GridBagConstraints(1, row, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); row++; unmodifiableAttributesPanel.add(ownerIdLabel, new GridBagConstraints(0, row, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, insetsDefault, 0, 0)); unmodifiableAttributesPanel.add(ownerIdTextField, new GridBagConstraints(1, row, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); row++; unmodifiableAttributesPanel.add(bucketNameLabel, new GridBagConstraints(0, row, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, insetsDefault, 0, 0)); unmodifiableAttributesPanel.add(bucketLocationTextField, new GridBagConstraints(1, row, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); // Build metadata table. objectMetadataTableModel = new DefaultTableModel(new Object[] { "Name", "Value" }, 0) { private static final long serialVersionUID = -3762866886166776851L; public boolean isCellEditable(int row, int column) { return isModifyMode(); } }; metadataTableSorter = new TableSorter(objectMetadataTableModel); metadataTable = skinsFactory.createSkinnedJTable("MetadataTable"); metadataTable.setModel(metadataTableSorter); metadataTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting() && removeMetadataItemButton != null) { int row = metadataTable.getSelectedRow(); removeMetadataItemButton.setEnabled(row >= 0); } } }); metadataTableSorter.setTableHeader(metadataTable.getTableHeader()); metadataTableSorter.setSortingStatus(0, TableSorter.ASCENDING); metadataContainer.add(new JScrollPane(metadataTable), new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, insetsHorizontalSpace, 0, 0)); // Add/remove buttons for metadata table. removeMetadataItemButton = skinsFactory.createSkinnedJButton("ObjectPropertiesAddMetadataButton"); removeMetadataItemButton.setEnabled(false); removeMetadataItemButton.setToolTipText("Remove the selected metadata item(s)"); guiUtils.applyIcon(removeMetadataItemButton, "/images/nuvola/16x16/actions/viewmag-.png"); removeMetadataItemButton.addActionListener(this); removeMetadataItemButton.setActionCommand("removeMetadataItem"); addMetadataItemButton = skinsFactory.createSkinnedJButton("ObjectPropertiesAddMetadataButton"); addMetadataItemButton.setToolTipText("Add a new metadata item"); guiUtils.applyIcon(addMetadataItemButton, "/images/nuvola/16x16/actions/viewmag+.png"); addMetadataItemButton.setActionCommand("addMetadataItem"); addMetadataItemButton.addActionListener(this); metadataButtonsContainer.add(removeMetadataItemButton, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, insetsZero, 0, 0)); metadataButtonsContainer.add(addMetadataItemButton, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, insetsZero, 0, 0)); metadataContainer.add(metadataButtonsContainer, new GridBagConstraints(0, 1, 1, 1, 1, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, insetsHorizontalSpace, 0, 0)); metadataButtonsContainer.setVisible(false); // OK Button. okButton = skinsFactory.createSkinnedJButton("ObjectPropertiesOKButton"); okButton.setText("OK"); okButton.setActionCommand("OK"); okButton.addActionListener(this); // Cancel Button. cancelButton = null; cancelButton = skinsFactory.createSkinnedJButton("ObjectPropertiesCancelButton"); cancelButton.setText("Cancel"); cancelButton.setActionCommand("Cancel"); cancelButton.addActionListener(this); cancelButton.setVisible(false); // Recognize and handle ENTER, ESCAPE, PAGE_UP, and PAGE_DOWN key presses. this.getRootPane().setDefaultButton(okButton); this.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "ESCAPE"); this.getRootPane().getActionMap().put("ESCAPE", new AbstractAction() { private static final long serialVersionUID = -7768790936535999307L; public void actionPerformed(ActionEvent actionEvent) { setVisible(false); } }); this.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("PAGE_UP"), "PAGE_UP"); this.getRootPane().getActionMap().put("PAGE_UP", new AbstractAction() { private static final long serialVersionUID = -6324229423705756219L; public void actionPerformed(ActionEvent actionEvent) { previousObjectButton.doClick(); } }); this.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("PAGE_DOWN"), "PAGE_DOWN"); this.getRootPane().getActionMap().put("PAGE_DOWN", new AbstractAction() { private static final long serialVersionUID = -5808972377672449421L; public void actionPerformed(ActionEvent actionEvent) { nextObjectButton.doClick(); } }); // Put it all together. row = 0; JPanel container = skinsFactory.createSkinnedJPanel("ObjectPropertiesPanel"); container.setLayout(new GridBagLayout()); container.add(unmodifiableAttributesPanel, new GridBagConstraints(0, row++, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0)); // Object previous and next buttons, if we have multiple objects. previousObjectButton = skinsFactory.createSkinnedJButton("ObjectPropertiesPreviousButton"); guiUtils.applyIcon(previousObjectButton, "/images/nuvola/16x16/actions/1leftarrow.png"); previousObjectButton.addActionListener(this); previousObjectButton.setEnabled(false); nextObjectButton = skinsFactory.createSkinnedJButton("ObjectPropertiesNextButton"); guiUtils.applyIcon(nextObjectButton, "/images/nuvola/16x16/actions/1rightarrow.png"); nextObjectButton.addActionListener(this); nextObjectButton.setEnabled(false); currentObjectLabel = skinsFactory.createSkinnedJHtmlLabel("ObjectPropertiesCurrentObjectLabel"); currentObjectLabel.setHorizontalAlignment(JLabel.CENTER); nextPreviousPanel = skinsFactory.createSkinnedJPanel("ObjectPropertiesNextPreviousPanel"); nextPreviousPanel.setLayout(new GridBagLayout()); nextPreviousPanel.add(previousObjectButton, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, insetsZero, 0, 0)); nextPreviousPanel.add(currentObjectLabel, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, insetsHorizontalSpace, 0, 0)); nextPreviousPanel.add(nextObjectButton, new GridBagConstraints(2, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, insetsZero, 0, 0)); container.add(nextPreviousPanel, new GridBagConstraints(0, row, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0)); nextPreviousPanel.setVisible(false); row++; JHtmlLabel metadataLabel = skinsFactory.createSkinnedJHtmlLabel("MetadataLabel"); metadataLabel.setText("<html><b>Metadata Attributes</b></html>"); metadataLabel.setHorizontalAlignment(JLabel.CENTER); container.add(metadataLabel, new GridBagConstraints(0, row++, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsVerticalSpace, 0, 0)); container.add(metadataContainer, new GridBagConstraints(0, row++, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, insetsZero, 0, 0)); // Destination Access Control List setting. destinationPanel = skinsFactory.createSkinnedJPanel("DestinationPanel"); destinationPanel.setLayout(new GridBagLayout()); JPanel actionButtonsPanel = skinsFactory.createSkinnedJPanel("ObjectPropertiesActionButtonsPanel"); actionButtonsPanel.setLayout(new GridBagLayout()); actionButtonsPanel.add(cancelButton, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0)); actionButtonsPanel.add(okButton, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0)); cancelButton.setVisible(false); container.add(actionButtonsPanel, new GridBagConstraints(0, row++, 3, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, insetsDefault, 0, 0)); this.getContentPane().add(container); this.pack(); this.setSize(new Dimension(450, 500)); this.setLocationRelativeTo(this.getOwner()); }
From source file:org.jtrfp.trcl.gui.ConfigWindow.java
public ConfigWindow() { setTitle("Settings"); setSize(340, 540);/*from w ww . ja va2 s . c o m*/ if (config == null) config = new TRConfiguration(); JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); getContentPane().add(tabbedPane, BorderLayout.CENTER); JPanel generalTab = new JPanel(); tabbedPane.addTab("General", new ImageIcon(ConfigWindow.class .getResource("/org/freedesktop/tango/22x22/mimetypes/application-x-executable.png")), generalTab, null); GridBagLayout gbl_generalTab = new GridBagLayout(); gbl_generalTab.columnWidths = new int[] { 0, 0 }; gbl_generalTab.rowHeights = new int[] { 0, 188, 222, 0 }; gbl_generalTab.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; gbl_generalTab.rowWeights = new double[] { 0.0, 1.0, 0.0, Double.MIN_VALUE }; generalTab.setLayout(gbl_generalTab); JPanel settingsLoadSavePanel = new JPanel(); GridBagConstraints gbc_settingsLoadSavePanel = new GridBagConstraints(); gbc_settingsLoadSavePanel.insets = new Insets(0, 0, 5, 0); gbc_settingsLoadSavePanel.anchor = GridBagConstraints.WEST; gbc_settingsLoadSavePanel.gridx = 0; gbc_settingsLoadSavePanel.gridy = 0; generalTab.add(settingsLoadSavePanel, gbc_settingsLoadSavePanel); settingsLoadSavePanel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Overall Settings", TitledBorder.LEADING, TitledBorder.TOP, null, null)); FlowLayout flowLayout_1 = (FlowLayout) settingsLoadSavePanel.getLayout(); flowLayout_1.setAlignment(FlowLayout.LEFT); JButton btnSave = new JButton("Export..."); btnSave.setToolTipText("Export these settings to an external file"); settingsLoadSavePanel.add(btnSave); btnSave.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { exportSettings(); } }); JButton btnLoad = new JButton("Import..."); btnLoad.setToolTipText("Import an external settings file"); settingsLoadSavePanel.add(btnLoad); btnLoad.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { importSettings(); } }); JButton btnConfigReset = new JButton("Reset"); btnConfigReset.setToolTipText("Reset all settings to defaults"); settingsLoadSavePanel.add(btnConfigReset); btnConfigReset.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { defaultSettings(); } }); JPanel registeredPODsPanel = new JPanel(); registeredPODsPanel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Registered PODs", TitledBorder.LEFT, TitledBorder.TOP, null, null)); GridBagConstraints gbc_registeredPODsPanel = new GridBagConstraints(); gbc_registeredPODsPanel.insets = new Insets(0, 0, 5, 0); gbc_registeredPODsPanel.fill = GridBagConstraints.BOTH; gbc_registeredPODsPanel.gridx = 0; gbc_registeredPODsPanel.gridy = 1; generalTab.add(registeredPODsPanel, gbc_registeredPODsPanel); GridBagLayout gbl_registeredPODsPanel = new GridBagLayout(); gbl_registeredPODsPanel.columnWidths = new int[] { 272, 0 }; gbl_registeredPODsPanel.rowHeights = new int[] { 76, 0, 0 }; gbl_registeredPODsPanel.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; gbl_registeredPODsPanel.rowWeights = new double[] { 1.0, 1.0, Double.MIN_VALUE }; registeredPODsPanel.setLayout(gbl_registeredPODsPanel); JPanel podListPanel = new JPanel(); GridBagConstraints gbc_podListPanel = new GridBagConstraints(); gbc_podListPanel.insets = new Insets(0, 0, 5, 0); gbc_podListPanel.fill = GridBagConstraints.BOTH; gbc_podListPanel.gridx = 0; gbc_podListPanel.gridy = 0; registeredPODsPanel.add(podListPanel, gbc_podListPanel); podListPanel.setLayout(new BorderLayout(0, 0)); JScrollPane podListScrollPane = new JScrollPane(); podListPanel.add(podListScrollPane, BorderLayout.CENTER); podList = new JList(podLM); podList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); podListScrollPane.setViewportView(podList); JPanel podListOpButtonPanel = new JPanel(); podListOpButtonPanel.setBorder(null); GridBagConstraints gbc_podListOpButtonPanel = new GridBagConstraints(); gbc_podListOpButtonPanel.anchor = GridBagConstraints.NORTH; gbc_podListOpButtonPanel.gridx = 0; gbc_podListOpButtonPanel.gridy = 1; registeredPODsPanel.add(podListOpButtonPanel, gbc_podListOpButtonPanel); FlowLayout flowLayout = (FlowLayout) podListOpButtonPanel.getLayout(); flowLayout.setAlignment(FlowLayout.LEFT); JButton addPodButton = new JButton("Add..."); addPodButton.setIcon( new ImageIcon(ConfigWindow.class.getResource("/org/freedesktop/tango/16x16/actions/list-add.png"))); addPodButton.setToolTipText("Add a POD to the registry to be considered when running a game."); podListOpButtonPanel.add(addPodButton); addPodButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { addPOD(); } }); JButton removePodButton = new JButton("Remove"); removePodButton.setIcon(new ImageIcon( ConfigWindow.class.getResource("/org/freedesktop/tango/16x16/actions/list-remove.png"))); removePodButton.setToolTipText("Remove a POD file from being considered when playing a game"); podListOpButtonPanel.add(removePodButton); removePodButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { podLM.removeElement(podList.getSelectedValue()); } }); JButton podEditButton = new JButton("Edit..."); podEditButton.setIcon(null); podEditButton.setToolTipText("Edit the selected POD path"); podListOpButtonPanel.add(podEditButton); podEditButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { editPODPath(); } }); JPanel missionPanel = new JPanel(); GridBagConstraints gbc_missionPanel = new GridBagConstraints(); gbc_missionPanel.fill = GridBagConstraints.BOTH; gbc_missionPanel.gridx = 0; gbc_missionPanel.gridy = 2; generalTab.add(missionPanel, gbc_missionPanel); missionPanel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Missions", TitledBorder.LEADING, TitledBorder.TOP, null, null)); GridBagLayout gbl_missionPanel = new GridBagLayout(); gbl_missionPanel.columnWidths = new int[] { 0, 0 }; gbl_missionPanel.rowHeights = new int[] { 0, 0, 0 }; gbl_missionPanel.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; gbl_missionPanel.rowWeights = new double[] { 1.0, 0.0, Double.MIN_VALUE }; missionPanel.setLayout(gbl_missionPanel); JScrollPane scrollPane = new JScrollPane(); GridBagConstraints gbc_scrollPane = new GridBagConstraints(); gbc_scrollPane.insets = new Insets(0, 0, 5, 0); gbc_scrollPane.fill = GridBagConstraints.BOTH; gbc_scrollPane.gridx = 0; gbc_scrollPane.gridy = 0; missionPanel.add(scrollPane, gbc_scrollPane); missionList = new JList(missionLM); missionList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); scrollPane.setViewportView(missionList); JPanel missionListOpButtonPanel = new JPanel(); GridBagConstraints gbc_missionListOpButtonPanel = new GridBagConstraints(); gbc_missionListOpButtonPanel.anchor = GridBagConstraints.NORTH; gbc_missionListOpButtonPanel.gridx = 0; gbc_missionListOpButtonPanel.gridy = 1; missionPanel.add(missionListOpButtonPanel, gbc_missionListOpButtonPanel); JButton addVOXButton = new JButton("Add..."); addVOXButton.setIcon( new ImageIcon(ConfigWindow.class.getResource("/org/freedesktop/tango/16x16/actions/list-add.png"))); addVOXButton.setToolTipText("Add an external VOX file as a mission"); missionListOpButtonPanel.add(addVOXButton); addVOXButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { addVOX(); } }); final JButton removeVOXButton = new JButton("Remove"); removeVOXButton.setIcon(new ImageIcon( ConfigWindow.class.getResource("/org/freedesktop/tango/16x16/actions/list-remove.png"))); removeVOXButton.setToolTipText("Remove the selected mission"); missionListOpButtonPanel.add(removeVOXButton); removeVOXButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { missionLM.remove(missionList.getSelectedIndex()); } }); final JButton editVOXButton = new JButton("Edit..."); editVOXButton.setToolTipText("Edit the selected Mission's VOX path"); missionListOpButtonPanel.add(editVOXButton); editVOXButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { editVOXPath(); } }); missionList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent evt) { final String val = (String) missionList.getSelectedValue(); if (val == null) missionList.setSelectedIndex(0); else if (isBuiltinVOX(val)) { removeVOXButton.setEnabled(false); editVOXButton.setEnabled(false); } else { removeVOXButton.setEnabled(true); editVOXButton.setEnabled(true); } } }); JPanel soundTab = new JPanel(); tabbedPane.addTab("Sound", new ImageIcon( ConfigWindow.class.getResource("/org/freedesktop/tango/22x22/devices/audio-card.png")), soundTab, null); GridBagLayout gbl_soundTab = new GridBagLayout(); gbl_soundTab.columnWidths = new int[] { 0, 0 }; gbl_soundTab.rowHeights = new int[] { 65, 51, 70, 132, 0, 0, 0 }; gbl_soundTab.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; gbl_soundTab.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE }; soundTab.setLayout(gbl_soundTab); JPanel checkboxPanel = new JPanel(); GridBagConstraints gbc_checkboxPanel = new GridBagConstraints(); gbc_checkboxPanel.insets = new Insets(0, 0, 5, 0); gbc_checkboxPanel.fill = GridBagConstraints.BOTH; gbc_checkboxPanel.gridx = 0; gbc_checkboxPanel.gridy = 0; soundTab.add(checkboxPanel, gbc_checkboxPanel); chckbxLinearInterpolation = new JCheckBox("Linear Filtering"); chckbxLinearInterpolation.setToolTipText("Use the GPU's TMU to smooth playback of low-rate samples."); chckbxLinearInterpolation.setHorizontalAlignment(SwingConstants.LEFT); checkboxPanel.add(chckbxLinearInterpolation); chckbxLinearInterpolation.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { needRestart = true; } }); chckbxBufferLag = new JCheckBox("Buffer Lag"); chckbxBufferLag.setToolTipText("Improves efficiency, doubles latency."); checkboxPanel.add(chckbxBufferLag); JPanel modStereoWidthPanel = new JPanel(); FlowLayout flowLayout_2 = (FlowLayout) modStereoWidthPanel.getLayout(); flowLayout_2.setAlignment(FlowLayout.LEFT); modStereoWidthPanel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "MOD Stereo Width", TitledBorder.LEADING, TitledBorder.TOP, null, null)); GridBagConstraints gbc_modStereoWidthPanel = new GridBagConstraints(); gbc_modStereoWidthPanel.anchor = GridBagConstraints.NORTH; gbc_modStereoWidthPanel.insets = new Insets(0, 0, 5, 0); gbc_modStereoWidthPanel.fill = GridBagConstraints.HORIZONTAL; gbc_modStereoWidthPanel.gridx = 0; gbc_modStereoWidthPanel.gridy = 1; soundTab.add(modStereoWidthPanel, gbc_modStereoWidthPanel); modStereoWidthSlider = new JSlider(); modStereoWidthSlider.setPaintTicks(true); modStereoWidthSlider.setMinorTickSpacing(25); modStereoWidthPanel.add(modStereoWidthSlider); final JLabel modStereoWidthLbl = new JLabel("NN%"); modStereoWidthPanel.add(modStereoWidthLbl); JPanel bufferSizePanel = new JPanel(); FlowLayout flowLayout_3 = (FlowLayout) bufferSizePanel.getLayout(); flowLayout_3.setAlignment(FlowLayout.LEFT); bufferSizePanel.setBorder( new TitledBorder(null, "Buffer Size", TitledBorder.LEADING, TitledBorder.TOP, null, null)); GridBagConstraints gbc_bufferSizePanel = new GridBagConstraints(); gbc_bufferSizePanel.anchor = GridBagConstraints.NORTH; gbc_bufferSizePanel.insets = new Insets(0, 0, 5, 0); gbc_bufferSizePanel.fill = GridBagConstraints.HORIZONTAL; gbc_bufferSizePanel.gridx = 0; gbc_bufferSizePanel.gridy = 2; soundTab.add(bufferSizePanel, gbc_bufferSizePanel); audioBufferSizeCB = new JComboBox(); audioBufferSizeCB.setModel(new DefaultComboBoxModel(AudioBufferSize.values())); bufferSizePanel.add(audioBufferSizeCB); soundOutputSelectorGUI = new SoundOutputSelectorGUI(); soundOutputSelectorGUI.setBorder( new TitledBorder(null, "Output Driver", TitledBorder.LEADING, TitledBorder.TOP, null, null)); GridBagConstraints gbc_soundOutputSelectorGUI = new GridBagConstraints(); gbc_soundOutputSelectorGUI.anchor = GridBagConstraints.NORTH; gbc_soundOutputSelectorGUI.insets = new Insets(0, 0, 5, 0); gbc_soundOutputSelectorGUI.fill = GridBagConstraints.HORIZONTAL; gbc_soundOutputSelectorGUI.gridx = 0; gbc_soundOutputSelectorGUI.gridy = 3; soundTab.add(soundOutputSelectorGUI, gbc_soundOutputSelectorGUI); modStereoWidthSlider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent arg0) { modStereoWidthLbl.setText(modStereoWidthSlider.getValue() + "%"); needRestart = true; } }); JPanel okCancelPanel = new JPanel(); getContentPane().add(okCancelPanel, BorderLayout.SOUTH); okCancelPanel.setLayout(new BorderLayout(0, 0)); JButton btnOk = new JButton("OK"); btnOk.setToolTipText("Apply these settings and close the window"); okCancelPanel.add(btnOk, BorderLayout.WEST); btnOk.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { applySettings(); ConfigWindow.this.setVisible(false); } }); JButton btnCancel = new JButton("Cancel"); btnCancel.setToolTipText("Close the window without applying settings"); okCancelPanel.add(btnCancel, BorderLayout.EAST); JLabel lblConfigpath = new JLabel(TRConfiguration.getConfigFilePath().getAbsolutePath()); lblConfigpath.setIcon(null); lblConfigpath.setToolTipText("Default config file path"); lblConfigpath.setHorizontalAlignment(SwingConstants.CENTER); lblConfigpath.setFont(new Font("Dialog", Font.BOLD, 6)); okCancelPanel.add(lblConfigpath, BorderLayout.CENTER); btnCancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { ConfigWindow.this.setVisible(false); } }); }
From source file:org.kontalk.view.ThreadListView.java
ThreadListView(final View view, ThreadList threadList) { mView = view;// ww w . j a va2 s. c o m mThreadList = threadList; this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // right click popup menu mPopupMenu = new WebPopupMenu(); WebMenuItem editMenuItem = new WebMenuItem(Tr.tr("Edit Thread")); editMenuItem.setToolTipText(Tr.tr("Edit this thread")); editMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { ThreadItem t = ThreadListView.this.getSelectedItem(); JDialog editUserDialog = new EditThreadDialog(t); editUserDialog.setVisible(true); } }); mPopupMenu.add(editMenuItem); WebMenuItem deleteMenuItem = new WebMenuItem(Tr.tr("Delete Thread")); deleteMenuItem.setToolTipText(Tr.tr("Delete this thread")); deleteMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { String warningText = Tr.tr("Permanently delete all messages in this thread?"); int selectedOption = WebOptionPane.showConfirmDialog(ThreadListView.this, warningText, Tr.tr("Please Confirm"), WebOptionPane.OK_CANCEL_OPTION, WebOptionPane.WARNING_MESSAGE); if (selectedOption == WebOptionPane.OK_OPTION) { ThreadItem threadItem = ThreadListView.this.getSelectedItem(); mThreadList.delete(threadItem.mValue.getID()); } } }); mPopupMenu.add(deleteMenuItem); // actions triggered by selection this.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) return; mView.selectedThreadChanged(ThreadListView.this.getSelectedValue()); } }); // actions triggered by mouse events this.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { check(e); } @Override public void mouseReleased(MouseEvent e) { check(e); } private void check(MouseEvent e) { if (e.isPopupTrigger()) { int row = ThreadListView.this.rowAtPoint(e.getPoint()); ThreadListView.this.setSelectedItem(row); ThreadListView.this.showPopupMenu(e); } } }); this.updateOnEDT(null); }