@Override public JComponent getContent() { if (this.obj == null) { throw new IllegalStateException("No object set."); } // TODO: Make this nicer later. if (this.obj instanceof Chapter) { Chapter c = (Chapter) this.obj; JComponent t = UIUtils.getChapterInfoPreview(c, null, this.viewer); if (t == null) { // May be a fake chapter, return null. return null; } t.setSize(new Dimension(300, Short.MAX_VALUE)); return t; } else { String firstLine = "<b><i>No description.</i></b>"; String t = (obj.getDescription() != null ? obj.getDescription().getText() : null); if ((t != null) && (t.length() > 0)) { firstLine = new Paragraph(t, 0).getFirstSentence().getText(); } JEditorPane desc = UIUtils.createHelpTextPane(firstLine, null); FormLayout fl = new FormLayout("380px", "p"); PanelBuilder pb = new PanelBuilder(fl); CellConstraints cc = new CellConstraints(); pb.add(desc, cc.xy(1, 1)); desc.setAlignmentX(Component.LEFT_ALIGNMENT); JPanel p = pb.getPanel(); p.setOpaque(true); p.setBackground(UIUtils.getComponentColor()); return p; } }
public HideablePopup(E viewer) { super(BoxLayout.Y_AXIS); this.viewer = viewer; this.setOpaque(true); this.setBackground(UIUtils.getComponentColor()); this.setBorder( new CompoundBorder( com.quollwriter.ui.components.UIUtils.internalPanelDropShadow, UIUtils.createLineBorder())); final HideablePopup _this = this; this.addMouseListener( new MouseAdapter() { public void mouseEntered(MouseEvent ev) { if (_this.hideTimer != null) { _this.hideTimer.stop(); } } public void mouseExited(MouseEvent ev) { if (_this.hideTimer != null) { Point p = new Point(0, 0); SwingUtilities.convertPointToScreen(p, _this); Rectangle tBounds = _this.getBounds(null); tBounds.x = p.x; tBounds.y = p.y; if (!tBounds.contains(ev.getLocationOnScreen())) { _this.hideTimer.start(); } } } }); }