⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 searchpanel.java

📁 myjxta是用jxta开发的一个p2p通讯软件 有聊天 文件共享 视频3大功能 界面采用swing
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        return tb;    }//    private JProgressBar createProgress() {//        this.progress = new DefaultBoundedRangeModel(0, MAX, 0, MAX);////        JProgressBar pb =//            new JProgressBar(this.progress) {//                final int SECOND = 1000;//                final int MINUTE = SECOND * 60;//                final int HOUR = MINUTE * 60;////                //public Dimension getPreferredSize() {//                //    return new Dimension(150,//                //                         super.getPreferredSize().height);//                //}////                public String getString() {//                    int r = MAX - progress.getValue();//                    int h = r / HOUR;//                    int m = (r - h * HOUR) / MINUTE;//                    int s = (r - h * HOUR - m * MINUTE) / SECOND;////                    return (h < 10 ? "0" : "") + h + ":" +//                           (m < 10 ? "0" : "") + m + ":" +//                           (s < 10 ? "0" : "") + s;//                }//            };////        pb.setStringPainted(true);////        return pb;//    }//remove!//    private JButton createDismiss() {//        JButton b = new JButton(new AbstractAction() {//            public void actionPerformed(ActionEvent ae) {//                dismiss();//            }//        });////        b.setText(STRINGS.getString("action.dismiss"));//        b.addKeyListener(new AbstractButtonKeyListener(b) {//             public void keyReleased(KeyEvent ke) {//                 getButton().getAction().actionPerformed(null);//             }//         });////        return b;//    }    private JTable createResults() {        JTable t = new JTable();        t.setShowHorizontalLines(false);        t.setShowVerticalLines(false);        t.setCellSelectionEnabled(false);        t.setColumnSelectionAllowed(false);        t.setRowSelectionAllowed(false);        t.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);        if (this.results != null) {            this.results.addTableModelListener(new TableModelListener() {                public void tableChanged(TableModelEvent tme) {                    JxtaNode jn = null;                    JxtaNode pn = null;                    Object o = null;                    for (int i = tme.getFirstRow(); i < tme.getLastRow() + 1; i++) {                        o = results.getData(tme.getFirstRow());                        // xxx: generalize                        if (o != null) {                            if (o instanceof Group) {                                Group g = (Group) o;                                jn = new GroupNode(g);                                pn = new GroupNode(g.getParentGroup());                            } else if (o instanceof Peer) {                                jn = new PeerNode((Peer) o, group);                                pn = new GroupNode(group);                            } else if (o instanceof Share) {                                jn = new ShareNode((Share) o, group, ShareNode.REMOTE_SHARE);                                pn = new GroupNode(group);                            }                        }                        if (jn != null) {                            jn.setParent(pn);                            myjxta.addJxtaNode(jn);                        }                    }                }            });            t.setModel(this.results);        }        return t;    }    private void checkState() {        if (this.modifier != null &&                this.query != null &&                this.search != null) {            boolean isEquality =                    ((SearchModifier) this.modifierModel.getSelectedItem()).isEquality();            this.search.setEnabled(! isEquality ||                    (isEquality &&                            this.query.getText().trim().length() > 0));        }    }    private void search() {        if (this.search.getModel().isSelected()) {            start();        } else {            stop();        }    }    private String getTerm() {        return ((SearchModifier) this.modifierModel.getSelectedItem()).                createTerm(this.query.getText());    }    private void start() {        startUI();        startSearch();        startTimer();    }    private void stop() {        stopTimer();        stopSearch();        stopUI();    }    private void startUI() {        for (int i = 0; i < this.results.getRowCount(); i++) {            this.results.removeRow(i);        }        this.search.setText(STRINGS.getString("action.stop"));        this.modifier.setEnabled(false);        this.query.setEnabled(false);        if (this.getParent() instanceof JTabbedPane) {            JTabbedPane jTabbedPane = ((JTabbedPane) this.getParent());            int i = jTabbedPane.indexOfComponent(this);            jTabbedPane.setTitleAt(i, this.searcher.getLabel() + ": " + getTerm());        } else {            throw new IllegalStateException("Search panel is not located inside a tabbed panel?");        }    }    private void startSearch() {        this.searcher.start(getTerm());        this.view.setStatus(STRINGS.getString("status.search.start") +                " " + this.searcher.getLabel() + " is " + getTerm());    }    private void stopUI() {        this.search.setText(STRINGS.getString("action.start"));        this.modifier.setEnabled(true);        this.query.setEnabled(true);    }    private void stopSearch() {        this.searcher.stop();        this.view.setStatus(STRINGS.getString("status.search.stop") +                " " + this.searcher.getLabel() + " is " + getTerm());    }    private void startTimer() {        if (this.timer == null &&                this.progress != null) {            if (this.progress.getValue() ==                    this.progress.getMaximum()) {                this.progress.setValue(0);            }            this.timer = new Timer();            this.timer.schedule(createTimerTask(), INTERVAL, INTERVAL);        }    }    private TimerTask createTimerTask() {        return new TimerTask() {            public void run() {                if (progress.getValue() <                        progress.getMaximum()) {                    updateProgress();                } else {                    progress.setValue(progress.getMaximum());                    ((JToggleButton.ToggleButtonModel)                            search.getModel()).setSelected(false);                    search.getAction().actionPerformed(null);                }            }        };    }    private void updateProgress() {        if (this.progress != null) {            this.progress.setValue(this.progress.getValue() + INTERVAL);        }    }    private void stopTimer() {        if (this.timer != null) {            this.timer.cancel();            this.timer = null;            this.search.setText(STRINGS.getString("action.start"));        }    }}class SearchListenerFactory {    public static SearchListener create(final int context,                                        final SearchTableModel results) {        SearchListener listener = null;        switch (context) {            case Searcher.GROUP:                listener = new AbstractSearchTableSearchListener() {                    public void add(JxtaNode node) {                        Group g = ((GroupNode) node).getGroup();                        PeerGroupAdvertisement pga =                                g.getPeerGroupAdvertisement();                        if (! inCache(pga.getID().toString())) {                            Object[] row = new Object[]{pga.getName(),                                    pga.getDescription()};                            process(results, context, g, row);                        }                    }                };                break;            case Searcher.PIPE:                listener = new AbstractSearchTableSearchListener() {                    public void add(JxtaNode node) {                        Peer p = ((PeerNode) node).getPeer();                        PipeAdvertisement pa = p.getPipeAdvertisement();                        if (! inCache(pa.getID().toString())) {                            Object[] row = new Object[]{p.getName()};                            process(results, context, p, row);                        }                    }                };                break;            case Searcher.SHARE:                listener = new AbstractSearchTableSearchListener() {                    public void add(JxtaNode node) {                        Share s = ((ShareNode) node).getShare();                        ContentAdvertisement ca = s.getContentAdvertisement();                        if (ca != null &&                                ! inCache(ca.getContentId().toString())) {                            Object[] row = new Object[]{ca.getName(), ca.getType(),                                    new Long(ca.getLength()).toString(), ca.getDescription()};                            process(results, context, s, row);                        }                    }                };                break;        }        return listener;    }}// xxx: generalizeabstract class AbstractSearchTableSearchListener        extends AbstractSearchListener {    protected void process(final SearchTableModel results,                           final int context, final Object o, final Object[] row) {        EventQueue.invokeLater(new Runnable() {            public void run() {                results.addRow(context, o, row);            }        });    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -