org.apache.poi.sl.usermodel.Slide Java Examples

The following examples show how to use org.apache.poi.sl.usermodel.Slide. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PPTSlideManager.java    From opencards with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public boolean showCardQuestion(Item item) {
    if (!doOptionalSync(item))
        return false;

    int cardIndex = item.getFlashCard().getCardIndex();
    ReversePolicy cardRevPolicy = item.getFlashCard().getTodaysRevPolicy();

    // note:
    // The random-reverse mode is encoded directly in the flashcard in order to make its policy temporary
    // persistent during the todaysltm-sessions
    Slide curSlide = ((HSLFSlideShow) slideShow).getSlides().get(cardIndex - 1);

    switch (cardRevPolicy) {
        case NORMAL:
            showCardQuestion(curSlide);
            break;
        case REVERSE:
            showCardContent(curSlide);
            break;
        default:
            throw new RuntimeException("unsupported reverse policy");
    }

    return true;
}
 
Example #2
Source File: PresentationSlide.java    From Quelea with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new presentation slide.
 *
 * @param slide the underlying apache POI slide.
 */
public PresentationSlide(Slide slide, int numSlide) {
    SlideShow slideshow = slide.getSlideShow();
    if (Math.abs(slideshow.getPageSize().getHeight() - HEIGHT) > 0.1) {
        int adjustHeight = HEIGHT;
        int adjustWidth = (int) ((adjustHeight / slideshow.getPageSize().getHeight()) * slideshow.getPageSize().getWidth());
        scaleWidth = (double) adjustWidth / slideshow.getPageSize().getWidth();
        scaleHeight = (double) adjustHeight / slideshow.getPageSize().getHeight();
        slideshow.setPageSize(new Dimension(adjustWidth, adjustHeight));
    }
    BufferedImage originalImage = new BufferedImage((int) slideshow.getPageSize().getWidth(), (int) slideshow.getPageSize().getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = originalImage.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    try {
        g2.setTransform(AffineTransform.getScaleInstance(scaleWidth, scaleHeight));
        slide.draw(g2);
    } catch (Exception ex) {
        if (QueleaProperties.get().getUsePP()) {
            LOGGER.log(Level.INFO, "Couldn't use library to generate thumbnail, using default");
            draw(g2, originalImage.getWidth(), originalImage.getHeight(), numSlide);
        } else {
            throw ex;
        }
    }
    image = new WritableImage(originalImage.getWidth(), originalImage.getHeight());
    SwingFXUtils.toFXImage(originalImage, image);
    originalImage.flush();
    originalImage = null;
}
 
Example #3
Source File: DrawTextParagraph.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected String getRenderableText(Graphics2D graphics, TextRun tr) {
    if (tr.getFieldType() == FieldType.SLIDE_NUMBER) {
        Slide<?,?> slide = (Slide<?,?>)graphics.getRenderingHint(Drawable.CURRENT_SLIDE);
        return (slide == null) ? "" : Integer.toString(slide.getSlideNumber());
    }
    StringBuilder buf = new StringBuilder();
    TextCap cap = tr.getTextCap();
    String tabs = null;
    for (char c : tr.getRawText().toCharArray()) {
        switch (c) {
            case '\t':
                if (tabs == null) {
                    tabs = tab2space(tr);
                }
                buf.append(tabs);
                break;
            case '\u000b':
                buf.append('\n');
                break;
            default:
                switch (cap) {
                    case ALL: c = Character.toUpperCase(c); break;
                    case SMALL: c = Character.toLowerCase(c); break;
                    case NONE: break;
                }

                buf.append(c);
                break;
        }
    }

    return buf.toString();
}
 
Example #4
Source File: DrawFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public Drawable getDrawable(Shape<?,?> shape) {
    if (shape instanceof TextBox) {
        return getDrawable((TextBox<?,?>)shape);
    } else if (shape instanceof FreeformShape) {
        return getDrawable((FreeformShape<?,?>)shape);
    } else if (shape instanceof TextShape) {
        return getDrawable((TextShape<?,?>)shape);
    } else if (shape instanceof TableShape) {
        return getDrawable((TableShape<?,?>)shape);
    } else if (shape instanceof GroupShape) {
        return getDrawable((GroupShape<?,?>)shape);
    } else if (shape instanceof PictureShape) {
        return getDrawable((PictureShape<?,?>)shape);
    } else if (shape instanceof GraphicalFrame) {
        return getDrawable((GraphicalFrame<?,?>)shape);
    } else if (shape instanceof Background) {
        return getDrawable((Background<?,?>)shape);
    } else if (shape instanceof ConnectorShape) {
        return getDrawable((ConnectorShape<?,?>)shape);
    } else if (shape instanceof Slide) {
        return getDrawable((Slide<?,?>)shape);
    } else if (shape instanceof MasterSheet) {
        return getDrawable((MasterSheet<?,?>)shape);
    } else if (shape instanceof Sheet) {
        return getDrawable((Sheet<?,?>)shape);
    } else if (shape.getClass().isAnnotationPresent(DrawNotImplemented.class)) {
        return new DrawNothing(shape);
    }
    
    throw new IllegalArgumentException("Unsupported shape type: "+shape.getClass());
}
 
Example #5
Source File: DrawMasterSheet.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks if this {@code sheet} displays the specified shape.
 *
 * Subclasses can override it and skip certain shapes from drawings,
 * for instance, slide masters and layouts don't display placeholders
 */
@Override
protected boolean canDraw(Graphics2D graphics, Shape<?,?> shape) {
    Slide<?,?> slide = (Slide<?,?>)graphics.getRenderingHint(Drawable.CURRENT_SLIDE);
    if (shape instanceof SimpleShape) {
        // in XSLF, slidenumber and date shapes aren't marked as placeholders opposed to HSLF
        Placeholder ph = ((SimpleShape<?,?>)shape).getPlaceholder();
        if (ph != null) {
            return slide.getDisplayPlaceholder(ph);
        }
    }
    return slide.getFollowMasterGraphics();
}
 
Example #6
Source File: PPTSlideManager.java    From opencards with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Test if item is in sync with given slide-show instance
 */
private boolean isItemOutOfSync(Item item, SlideShow slideShow) {
    final List<? extends Slide> allSlides = ((HSLFSlideShow) slideShow).getSlides();

    final int itemCardIndex = item.getFlashCard().getCardIndex();

    return itemCardIndex < 0 || (allSlides.size() < itemCardIndex - 1)
            || allSlides.get(itemCardIndex - 1).getTitle() == null
            || allSlides.get(itemCardIndex - 1).getTitle().hashCode() != item.getFlashCard().getCardID();
}
 
Example #7
Source File: PPTSlideRenderPanel.java    From opencards with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void configure(Slide slide, boolean showTitle, boolean showContent) {
    this.slide = (HSLFSlide) slide;

    this.showTitleShape = showTitle;
    this.showContent = showContent;

    repaint();
}
 
Example #8
Source File: DrawFactory.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public DrawSlide getDrawable(Slide<?,?> sheet) {
    return new DrawSlide(sheet);
}
 
Example #9
Source File: PPTSlideManager.java    From opencards with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void showCardContent(Slide curSlide) {
    getSlidePanel().configure(curSlide, false, true);
}
 
Example #10
Source File: PPTSlideManager.java    From opencards with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void showCardQuestion(Slide curSlide) {
    getSlidePanel().configure(curSlide, true, false);
}
 
Example #11
Source File: PPTSlideManager.java    From opencards with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public boolean showCompleteCard(Item item) {
    Slide curSlide = ((HSLFSlideShow) slideShow).getSlides().get(item.getFlashCard().getCardIndex() - 1);
    getSlidePanel().configure(curSlide, true, true);

    return true;
}