Results 1 to 14 of 14
Like Tree1Likes
  • 1 Post By willemjav

Thread: How to archive OpenOffice style page scrolling

  1. #1
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default How to archive OpenOffice style page scrolling

    How can one archive a OpenOffice style page scrolling in Java?
    I meen to say, there is a fixe rectangle thin line marking the page
    where all the text goes and each page can be scrolled vertical.

    open office - Google Search

    Would it be similar like this:

    Java Code:
    import java.awt.*;
    import java.awt.font.*;
    import java.text.*;
    
    public class ParagraphLayout {
      public static void main(String[] args) {
        Frame f = new ApplicationFrame("ParagraphLayout v1.0") {
          public void paint(Graphics g) {
            Graphics2D g2 = (Graphics2D)g;
    
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
    
            // From _One Hundred Years of Solitude_ by Gabriel Garcia Marquez.
            String s = "Jos\u00e9 Arcadio Buend\u00eda spent the long months " +
               "of the rainy season shut up in a small room that he " +
               "had built in the rear of the house so that no one " +
               "would disturb his experiments. Having completely abandoned " +
               "his domestic obligations, he spent entire nights in the " +
               "courtyard watching the course of the stars and he almost " +
               "contracted sunstroke from trying to establish an exact method " +
               "to ascertain noon. When he became an expert in the use and " +
               "manipulation of his instruments, he conceived a notion of " +
               "space that allowed him to navigate across unknown seas, " +
               "to visit uninhabited territories, and to establish " +
               "relations with splendid beings without having to leave " +
               "his study. That was the period in which he acquired the habit " +
               "of talking to himself, of walking through the house without " +
               "paying attention to anyone...";
            
            Font font = new Font("Serif", Font.PLAIN, 24);
            AttributedString as = new AttributedString(s);
            as.addAttribute(TextAttribute.FONT, font);
            AttributedCharacterIterator aci = as.getIterator();
            FontRenderContext frc = g2.getFontRenderContext();
            LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc);
            Insets insets = getInsets();
            float wrappingWidth = getSize().width - insets.left - insets.right; float x = insets.left;
            float y = insets.top;
    
            while (lbm.getPosition() < aci.getEndIndex()) {
              TextLayout textLayout = lbm.nextLayout(wrappingWidth);
              y += textLayout.getAscent();
              textLayout.draw(g2, x, y);
              y += textLayout.getDescent() + textLayout.getLeading();
              x = insets.left;
            }
          }
        };
        f.setVisible(true);
      }
    }

    Java Code:
    import java.awt.Dimension;
    import java.awt.Frame;
    import java.awt.Toolkit;
    
    public class ApplicationFrame extends Frame {
            public ApplicationFrame() {
                this("ApplicationFrame v1.0");
            }
            public ApplicationFrame(String title) {
                    super(title);
                    createUI();
            }
            protected void createUI() {
                setSize(500, 400);
                center();
    
                addWindowListener(new java.awt.event.WindowAdapter()  {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e ) {
                        dispose();
                        System.exit(0);
                    }
                });
            }
    
            public void center() {
                Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
                Dimension frameSize = getSize();
                int x = (screenSize.width - frameSize.width) / 2;
                int y = (screenSize.height - frameSize.height) / 2;
                setLocation(x, y);
    
    
            }
    }
    Last edited by willemjav; 03-17-2014 at 09:03 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,969
    Rep Power
    8

    Default Re: How to archive OpenOffice style page scrolling

    I don't really understand your question. Are you asking how to put a gray border around a scrollable component?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: How to archive OpenOffice style page scrolling

    take a look at the Open Office text application which I believe was written in Java?
    Each text page appears inside a fixed rectangle. And when there are more pages they scroll down,
    like a JPanel that scrolls with several rectangles which all together do not fit on the screen!

    open office - Buscar con Google

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,969
    Rep Power
    8

    Default Re: How to archive OpenOffice style page scrolling

    I know what OpenOffice looks like, but I don't know which part of OpenOffice you're talking about. Are you talking about how the text is separated into separate pages? If so, here are some links to get your started:

    Pagination in the JEditor Pane
    Paginated printing of JEditorPane/JTextPane content.
    JEditorPane/JTextPane structure tool.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: How to archive OpenOffice style page scrolling

    Great Kevin I think the first link is what I've been looking for!

  6. #6
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: How to archive OpenOffice style page scrolling

    Wow so much code for such "simple" thing,
    but ok I asked for it and I got it!

  7. #7
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,050
    Rep Power
    6

    Default Re: How to archive OpenOffice style page scrolling

    Keep in mind: things that are functionally easy can still be technically difficult to implement. Don't be fooled by how easy something sounds or you're going to make many a mistake in your disadvantage when passing out estimations in the future.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  8. #8
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: How to archive OpenOffice style page scrolling

    gimbal2, you're being rather cryptic, could you be a little more specific please?

  9. #9
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,050
    Rep Power
    6

    Default Re: How to archive OpenOffice style page scrolling

    Great, now you challenge me to come up with a decent real-life example. Challenge accepted, but I'll need to think about it. Stupidly enough I had one not too long ago but I forgot the exact details.

    Alright, still a bit vague but here goes: a real example from my average working day. I work for a marine insurance company and work on their internally used software stack. At one point in time, there was a request for a change to do the registration of booking of premium just a tiny bit different (to actually correct a flaw that had been in the system for a long time already). After thinking long and hard about it, our IT manager came up with a beautiful solution that was incredibly simple and just couldn't fail - the fix took 15 minutes and all the new bookings were perfect.

    Nobody did consider the fact that we have historical data which needs to work according to the OLD way of calculating things; especially invoices are already sent out and paid for and so cannot change, so if 500 dollars was booked in 2012, then in 2014 the system should still come up with 500 dollars when recalculating the data. But it didn't, it was now working according to that tiny little change that was implemented and it came up with for example 510 dollars, making all kinds of reports go out of sync. It took 3 days to adapt all the reports to the new way of working and to get the application to recognize that it needed to use two different ways of calculating the end result based on the time period that the data was created.

    15 minutes of work turned into a 3 days of work and an entire company of angry people. All because someone said that it was simple. And it WAS simple; the technical implementation however was very difficult.
    Last edited by gimbal2; 03-19-2014 at 03:30 PM.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  10. #10
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,969
    Rep Power
    8

    Default Re: How to archive OpenOffice style page scrolling

    This happens all the time, and in fact it just happened to you when you expected the pagination display to be easier. Things that seem easy are often much harder than you expect, and things that other people think will be hard are sometimes actually pretty trivial.

    An example from my job: our software contains a map that shows different stuff on it. One of my bosses says "I know this sounds hard, but can we add a new layer to the map that shows hand-drawn figures on top of the map?" Actually that's pretty easy! Another one of my bosses says "This should only take you a couple hours, so can you add an option to show two maps side by side?" Actually that would take a month of development!
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  11. #11
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: How to archive OpenOffice style page scrolling

    I'll be patient....

    Java Code:
    while (true) {
                 
             }
    gimbal2 likes this.

  12. #12
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,050
    Rep Power
    6

    Default Re: How to archive OpenOffice style page scrolling

    I actually ninja'd you ;) See previous post.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  13. #13
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: How to archive OpenOffice style page scrolling

    But anyway a happy ending for the firm!
    It made 10 $ more, right?
    Thanks for your small elaboration.

  14. #14
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: How to archive OpenOffice style page scrolling

    BTW this Java text writer stuff is all but simple!!

Similar Threads

  1. openoffice not loading via public ip
    By evan_earnest in forum Java Applets
    Replies: 0
    Last Post: 02-08-2011, 10:19 AM
  2. OpenOffice and NetBeans Graphic
    By V.J in forum SWT / JFace
    Replies: 1
    Last Post: 12-26-2010, 03:06 AM
  3. Using openoffice in java application
    By urzaaa in forum AWT / Swing
    Replies: 5
    Last Post: 08-25-2008, 01:38 PM
  4. Groovy For OpenOffice 0.2
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-15-2007, 04:49 PM
  5. Groovy For OpenOffice 0.1
    By levent in forum Java Software
    Replies: 0
    Last Post: 06-10-2007, 01:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •