public Tab get(Connection connection, Entity entity) { for (Tab t : tabList.getItems()) { if (t.getConnection().equals(connection) && t.getEntity().equals(entity)) { return t; } } return create(connection, entity); }
public void addUserStatusMessage( User source, Message message, MessageRow.Type type, TabAction action) { for (Tab tab : getItems()) { if (tab.getEntity().equals(source) || (tab.getEntity() instanceof Channel && ((Channel) tab.getEntity()).getUsers().contains(source))) { tab.getContentPane().getMessagePane().addRow(new MessageRow(message, type)); if (action != null) { action.process(tab); } } } }
public void addUntargetedMessage(Connection connection, Message message, MessageRow.Type type) { Tab tab = getSelected(); if (tab == null || !tab.getConnection().equals(connection)) { tab = null; for (Tab _tab : getItems()) { if (_tab.getConnection().equals(connection)) { tab = _tab; break; } } if (tab == null) { tab = create(connection, connection.getServer()); } } tab.getContentPane().getMessagePane().addRow(new MessageRow(message, type)); }
@Override protected void updateItem(final Tab tab, boolean empty) { super.updateItem(tab, empty); if (tab != null) { tab.getUnreadProperty() .addListener( new ChangeListener<Boolean>() { @Override public void changed( ObservableValue<? extends Boolean> observableValue, Boolean oldValue, Boolean newValue) { if (newValue) { getStyleClass().add("unread"); } else { getStyleClass().remove("unread"); } } }); Entity entity = tab.getEntity(); setPrefHeight(32); if (entity instanceof Server) { setPrefHeight(40); Label net = new Label("network"); net.getStyleClass().add("network"); VBox box = new VBox(); Label name = new Label(entity.getName()); name.getStyleClass().add("network-name"); box.getChildren().addAll(net, name); setGraphic(box); } else if (entity instanceof Channel) { final Label label = new Label(entity.getName().substring(1)); label.getStyleClass().add("name"); final HBox box = new HBox(); box.getChildren().addAll(FontAwesome.createIcon(FontAwesome.COMMENTS), label); setGraphic(box); } else if (entity instanceof User) { final Label label = new Label(entity.getName()); label.getStyleClass().add("name"); final HBox box = new HBox(); box.getChildren().addAll(FontAwesome.createIcon(FontAwesome.USER), label); setGraphic(box); } } }
public void addTargetedMessage(Connection connection, Message message, MessageRow.Type type) { Entity target = message.getTarget(); if (target.equals(connection.getLocalUser())) { target = message.getSource(); } Tab tab = null; for (Tab _tab : getItems()) { if (_tab.getEntity().equals(target)) { tab = _tab; break; } } if (tab == null) { if (type == MessageRow.Type.PART && message.getSource().equals(connection.getLocalUser())) { return; } tab = create(connection, target); } tab.getContentPane().getMessagePane().addRow(new MessageRow(message, type)); }
public void changed(ObservableValue<? extends Tab> ov, Tab oldTab, Tab newTab) { try { if (newTab == null) { appPane.setContentPane(null); return; } newTab.setUnread(false); appPane.setContentPane(newTab.getContentPane()); final TextField inputField = appPane.getContentPane().getInputPane().getInputField(); Platform.runLater( new Runnable() { public void run() { inputField.requestFocus(); inputField.positionCaret(inputField.getText().length()); inputField.deselect(); } }); } catch (final NullPointerException npe) { System.err.println("NPE Caught in method: TabPane.TabClickedListener#changed()"); } }
public void close(Tab tab, boolean action) { if (getSelected().equals(tab)) { if (selectionModel.getSelectedIndex() == tabList.getItems().size()) { selectPrevious(); } else { selectNext(); } } { Iterator<Tab> it = tabList.getItems().iterator(); while (it.hasNext()) { Tab _tab = it.next(); if (_tab.equals(tab)) { it.remove(); if (action) { if (tab.getEntity() instanceof Channel) { appPane.getContentPane().getConnection().part((Channel) tab.getEntity()); } else if (tab.getEntity() instanceof Server) { appPane.getContentPane().getConnection().quit(""); } } break; } } } if (tab.getEntity() instanceof Server) { Iterator<Tab> it = tabList.getItems().iterator(); while (it.hasNext()) { Tab _tab = it.next(); if (_tab.getConnection().equals(tab.getConnection())) { close(_tab); } } } Mercury.saveConnections(); }
public SaveDialog(Frame parent) { super(parent, true); this.setLayout(new BorderLayout()); // gather unsaved tab Set<Tab> unsaved = new LinkedHashSet<>(); for (Tab tab : MainPanel.getAllTab()) { if (!tab.isSaved()) { unsaved.add(tab); } } if (unsaved.isEmpty()) { // close directly this.setTitle("Confirm close"); // upper labels JPanel labels = new JPanel(new FlowLayout(FlowLayout.LEFT, 11, 7)); labels.add(iconLabel); labels.add(new MyLabel(" Do you really want to close RefluxEdit?")); // buttons JPanel buttons = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 7)); buttons.add( new MyButton("YES") { { SaveDialog.this.getRootPane().setDefaultButton(this); this.setFocusPainted(true); } @Override public void actionPerformed(ActionEvent ev) { close = true; SaveDialog.this.setVisible(false); } }); buttons.add( new MyButton("NO") { { this.setFocusPainted(true); } @Override public void actionPerformed(ActionEvent ev) { close = false; SaveDialog.this.setVisible(false); } }); buttons.setBorder(new EmptyBorder(0, 0, 5, 0)); // this.add(labels, BorderLayout.CENTER); this.add(buttons, BorderLayout.PAGE_END); } else { // ask save changes this.setTitle("Unsaved changes"); // upper components: icon and list JPanel upper = new JPanel(new GridBagLayout()); JPanel listPane = new JPanel(new BorderLayout()); final DefaultListModel<Tab> listModel = new DefaultListModel<>(); final JList<Tab> tabList = new JList<>(listModel); tabList.setFont(f13); tabList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); tabList.setCellRenderer( new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent( JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel label = (JLabel) (super.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus)); if (value instanceof Tab) { String text = ((Tab) value).getTabLabel().getText(); label.setText(text.substring(1)); // remove "*" } return label; } }); for (Tab tab : unsaved) { listModel.addElement(tab); } tabList.getSelectionModel().setSelectionInterval(0, listModel.size() - 1); JScrollPane scrollPane = new JScrollPane(tabList); scrollPane.setPreferredSize(new Dimension(350, 170)); listPane.add(new MyLabel("The following tabs are unsaved:"), BorderLayout.PAGE_START); listPane.add(scrollPane, BorderLayout.CENTER); // setup upper GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.weightx = 0; c.weighty = 1; c.insets = new Insets(5, 5, 5, 5); c.anchor = GridBagConstraints.FIRST_LINE_START; upper.add(iconLabel, c); // c.gridx = 1; c.weightx = 1; c.fill = GridBagConstraints.BOTH; upper.add(listPane, c); // lower components: buttons JPanel buttons = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 7)); buttons.add( new MyButton("Save") { { this.setFocusPainted(true); this.setToolTipText("Save selected tab(s)"); SaveDialog.this.getRootPane().setDefaultButton(this); if (isMetal) { this.setPreferredSize(METAL_BUTTON_DIZE); } } @Override public void actionPerformed(ActionEvent ev) { for (Tab tab : tabList.getSelectedValuesList()) { if (tab.getFile() != null) { try { tab.save(); MainPanel.close(tab); listModel.removeElement(tab); } catch (Exception ex) { exception(ex); break; } } else { File file = FileChooser.showPreferredFileDialog( RefluxEdit.getInstance(), FileChooser.SAVE, new String[0]); if (file != null) { try { tab.save(file, false); MainPanel.close(tab); listModel.removeElement(tab); } catch (Exception ex) { exception(ex); break; } } } } if (listModel.size() == 0) { RefluxEdit.getInstance().close(); } } }); buttons.add( new MyButton("Discard") { { this.setFocusPainted(true); this.setToolTipText("Discard selected tab(s)"); if (isMetal) { this.setPreferredSize(METAL_BUTTON_DIZE); } } @Override public void actionPerformed(ActionEvent ev) { for (Tab tab : tabList.getSelectedValuesList()) { MainPanel.close(tab); listModel.removeElement(tab); } if (listModel.size() == 0) { RefluxEdit.getInstance().close(); } } }); buttons.add( new MyButton("Close") { { this.setFocusPainted(true); this.setToolTipText("Close RefluxEdit"); if (isMetal) { this.setPreferredSize(METAL_BUTTON_DIZE); } } @Override public void actionPerformed(ActionEvent ev) { SaveDialog.this.close = true; SaveDialog.this.setVisible(false); } }); buttons.add( new MyButton("Cancel") { { this.setFocusPainted(true); if (isMetal) { this.setPreferredSize(METAL_BUTTON_DIZE); } } @Override public void actionPerformed(ActionEvent ev) { SaveDialog.this.close = false; SaveDialog.this.setVisible(false); } }); this.add(upper, BorderLayout.CENTER); this.add(buttons, BorderLayout.PAGE_END); } }