public WelcomeMDIWindow(UISubsystem ui) throws Exception { super(ui.getMainWindow().getMDIManager(), "welcome", ui); this.ui = ui; Language.translateXUIElements(getClass(), xui.getXUIComponents()); BufferedReader r = new BufferedReader(new InputStreamReader(ui.getRl().getResourceStream("welcome.html"))); StringBuffer data = new StringBuffer(); String line = null; while ((line = r.readLine()) != null) { data.append(line); } setTitle(Language.getLocalizedString(getClass(), "title")); label = (JHtmlLabel) xui.getComponent("label"); label.setText(data.toString()); postInit(); }
private void init( String title, String message, int dialogType, int buttonType, boolean customTitle) throws Exception { if (customTitle) { setTitle(title); } else { setTitle(Language.getLocalizedString(getClass(), title)); } setLayout(new BorderLayout()); JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, 0)); this.keyListener = new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { String event = OptionDialog.this.eventKeyMap.get(Character.valueOf(e.getKeyChar())); if (event != null) { OptionDialog.this.actionPerformed(new ActionEvent(e.getSource(), e.getID(), event)); } } }; panel.addKeyListener(this.keyListener); if (imageIcons != null) { JLabel l = new JLabel(imageIcons[dialogType]); l.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); panel.add(l); panel.add(Box.createVerticalStrut(5)); } JHtmlLabel l = new JHtmlLabel() { @Override public Dimension getPreferredSize() { return new Dimension(400, super.getPreferredSize().height); } }; l.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); message = message.replace('[', '<'); message = message.replace(']', '>'); message = message.replaceAll("\r\n", "<br>"); message = message.replaceAll("\r", "<br>"); message = message.replaceAll("\n", "<br>"); l.setText(message); panel.add(l); add(panel, "Center"); panel = new JPanel(); panel.setLayout(new FlowLayout(1, 5, 5)); switch (buttonType) { case 0: panel.add(createButton(Language.getLocalizedString(getClass(), "ok"), "ok", "o", true)); break; case 1: panel.add(createButton(Language.getLocalizedString(getClass(), "yes"), "yes", "y", true)); panel.add(createButton(Language.getLocalizedString(getClass(), "no"), "no", "n", false)); break; case 2: panel.add(createButton(Language.getLocalizedString(getClass(), "yes"), "yes", "y", true)); panel.add(createButton(Language.getLocalizedString(getClass(), "no"), "no", "n", false)); panel.add( createButton(Language.getLocalizedString(getClass(), "cancel"), "cancel", "c", false)); break; case 3: panel.add(createButton(Language.getLocalizedString(getClass(), "ok"), "ok", "o", true)); panel.add( createButton(Language.getLocalizedString(getClass(), "cancel"), "cancel", "c", false)); } add(panel, "South"); setResizable(false); }
public SearchMDIWindow(final UISubsystem ui) throws Exception { super(ui.getMainWindow().getMDIManager(), "search", ui); this.ui = ui; fileTypeIcons = new ImageIcon[8]; for (int i = 0; i < fileTypeIcons.length; i++) { fileTypeIcons[i] = new ImageIcon(ui.getRl().getResource("gfx/filetypes/" + i + ".png")); } left = (JLabel) xui.getComponent("left"); right = (JLabel) xui.getComponent("right"); search = (JTextField) xui.getComponent("search1"); new CutCopyPastePopup(search); pacedRunner = new PacedRunner(500); JHtmlLabel label = (JHtmlLabel) xui.getComponent("label"); label.addHyperlinkListener( new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent e) { String s = e.getURL().toString(); s = s.substring(s.length() - 1); FileType ft = FileType.getFileTypeById(Integer.parseInt(s)); if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { try { ui.getMainWindow() .getMDIManager() .selectWindow(ui.getMainWindow().getSearchWindow()); ui.getMainWindow().getSearchWindow().searchForNewFilesOfType(ft); } catch (IOException e1) { ui.handleErrorInEventLoop(e1); } } else if (e.getEventType() == HyperlinkEvent.EventType.ENTERED) { ui.getMainWindow() .setStatusMessage( "Click here to search for new and popular files in type " + ft.description()); } } }); table = new JXTreeTable(model = new SearchTreeTableModel(ui.getCore(), pacedRunner)); table.setColumnControlVisible(true); table .getTableHeader() .addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { JTableHeader h = (JTableHeader) e.getSource(); TableColumnModel columnModel = h.getColumnModel(); int viewColumn = columnModel.getColumnIndexAtX(e.getX()); int column = columnModel.getColumn(viewColumn).getModelIndex(); if (column != -1) { switch (column) { case 0: model.getRoot().sortByName(); break; case 1: model.getRoot().sortBySize(); break; case 3: model.getRoot().sortByDaysAgo(); break; case 4: model.getRoot().sortBySources(); break; case 5: model.getRoot().sortBySpeed(); break; } } } }); table.addMouseMotionListener( new MouseMotionListener() { @Override public void mouseDragged(MouseEvent e) {} @Override public void mouseMoved(MouseEvent e) { if (table.getPathForLocation(e.getX(), e.getY()) != null) { SearchTreeNode n = (SearchTreeNode) table.getPathForLocation(e.getX(), e.getY()).getLastPathComponent(); if (n != null) { if (n instanceof FileNode) { FileNode fn = (FileNode) n; double d = fn.getTotalMaxCPS(); double r = ui.getCore().getSettings().getInternal().getRecordinspeed(); left.setText( "<html>" + fn.getListOfUsers(ui.getCore()) + " (Max speed: <b>" + TextUtils.formatByteSize((long) d) + "/s</b>, ETA: " + formatETA((int) Math.round(fn.getSize() / (d > r ? r : d))) + "</font>)</html>"); right.setText("<html><b>" + simplifyPath(fn) + "</b></html>"); } } } } private String formatETA(int eta) { if (eta < 0) { return "?"; } else if (eta <= 60) { return eta + " sec"; } else if (eta / 60 < 60) { return eta / 60 + " min"; } else { return (eta / 60 / 60) + "h " + (eta / 60 % 60) + "m"; } } }); table.addMouseListener( new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { maybeShowPopup(e); } @Override public void mousePressed(MouseEvent e) { maybeShowPopup(e); } @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() >= 2) { EVENT_download(null); } } private void maybeShowPopup(MouseEvent e) { if (e.isPopupTrigger()) { int row = table.rowAtPoint(e.getPoint()); boolean b = false; for (int r : table.getSelectedRows()) { if (r == row) { b = true; break; } } if (!b) { table.getSelectionModel().setSelectionInterval(row, row); } popup.show(e.getComponent(), e.getX(), e.getY()); } } }); table.setAutoCreateColumnsFromModel(false); table.setTreeCellRenderer(new NameCellRenderer()); table.getColumnModel().getColumn(1).setCellRenderer(new BytesizeCellRenderer()); table.getColumnModel().getColumn(3).setCellRenderer(new DaysOldCellRenderer()); table.getColumnModel().getColumn(4).setCellRenderer(new SourcesCellRenderer()); table.getColumnModel().getColumn(5).setCellRenderer(new SpeedCellRenderer()); table.getColumnModel().getColumn(0).setPreferredWidth(500); setFixedColumnSize(table.getColumnModel().getColumn(1), 50); setFixedColumnSize(table.getColumnModel().getColumn(2), 50); setFixedColumnSize(table.getColumnModel().getColumn(3), 55); setFixedColumnSize(table.getColumnModel().getColumn(4), 25); setFixedColumnSize(table.getColumnModel().getColumn(5), 40); table.getColumnExt(2).setVisible(false); // tricky! the index points to the visible columns! // table.getColumnExt(1).setVisible(false); ((JScrollPane) xui.getComponent("treepanel")).setViewportView(table); type = (JComboBox) xui.getComponent("type"); popup = (JPopupMenu) xui.getComponent("popup"); for (FileType v : FileType.values()) { type.addItem(v.description()); } setTitle("File search"); postInit(); }