Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #31933

Re: Vertical Text - part 3

From Knute Johnson <nospam@rabbitbrush.frazmtn.com>
Newsgroups comp.lang.java.programmer
Subject Re: Vertical Text - part 3
Date 2015-07-02 16:21 -0700
Organization A noiseless patient Spider
Message-ID <mn4h04$a17$1@dont-email.me> (permalink)
References <mn160m$anb$1@dont-email.me> <mn3d9d$qha$1@dont-email.me> <1980b894-6ca3-48f5-b70a-1628c56185e1@googlegroups.com> <mn3ic8$eq3$1@dont-email.me> <mn40en$ogv$3@dont-email.me>

Show all headers | View raw


On 7/2/2015 11:38, Martin Gregorie wrote:
> On Thu, 02 Jul 2015 10:36:19 -0400, Jeff Higgins wrote:
>
>> Anyway, after rereading Martin's post I see he doesn't have a JTable so
>> the pointer is pointless.
>>
> Yep: using a JTable was the first idea I thought of, but the screen
> layout doesn't match the JTable convention of a single header line
> followed by a set of identical data rows.
>
> Just so you know what I've been trying to describe, there's a screen shot
> of the rostering tool displaying some test data (only three instructors
> plus the special [NA] 'name') and four days) at:
>
> http://www.gregorie.org/temp/Screenshot%20-%20020715.jpg
>
> I've sliced out some blank screen area between the matrix and the error
> message and also a chunk on the right of the matrix - that's to make
> image a bit easier to read. This version is using Knute's HTML trick to
> display the list of instructor names above the matrix: you can see how
> tall even quite a small name becomes.
>
> The error message and associated red matrix cell describes why Barney
> RUBBLE can't be rostered on the 12th of April: the blue and green cells
> show successful duty allocations and the black one is an unrosterable day
> (also shown by all the duty slots being marked [NA]).
>
> In real life this screen would be showing 25 instructors and 57 rosterable
> days, i.e. the matrix would be 26 x 57 rather than 4 x 4 you're seeing.
>
>

If only Swing supported the line-height style!


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class test4 extends JPanel {
     String[] names = { "Charlie HORSE", "Martin GREGORIE", "Barney RUBBLE",
      "[NA]" };

     public test4() {
         super(new GridBagLayout());

         GridBagConstraints c = new GridBagConstraints();
         c.gridy = 0;

         for (String name : names) {
             VerticalText vt = new VerticalText(name,20,300);
             add(vt,c);
         }
     }

     class VerticalText extends JComponent {
         private final String message;
         private final int width;
         private final int height;

         public VerticalText(String message, int width, int height) {
             this.message = message.replaceAll("[\\[\\]]","");
             this.width = width;
             this.height = height;

             setFont(new Font("Monospaced",Font.BOLD,16));
             setPreferredSize(new Dimension(width,height));
         }

         public void paintComponent(Graphics g2d) {
             Graphics2D g = (Graphics2D)g2d;
             g.setColor(Color.LIGHT_GRAY);
             g.fillRect(0,0,getWidth(),getHeight());
             g.setColor(Color.BLACK);
             g.drawRect(0,0,getWidth()-1,getHeight()-1);
             String str = new StringBuilder(message).reverse().toString();
             char[] chars = str.toCharArray();
             FontMetrics metrics = g.getFontMetrics();
             double charHeight = metrics.getHeight();
             g.translate(
              (getWidth() - metrics.charWidth(' '))/2.0,
              getHeight()-5);
             for (int i=0; i<chars.length; i++) {
                 g.drawChars(chars,i,1,0,0);
                 g.translate(0,-charHeight+10);
             }
         }
     }

     public static void main(String... args) {
         EventQueue.invokeLater(() -> {
             JFrame f = new JFrame();
             f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
             f.add(new test4(),BorderLayout.CENTER);
             f.pack();
             f.setVisible(true);
         });
     }
}

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Vertical Text - part 3 Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-01 16:54 +0000
  Re: Vertical Text - part 3 Jeff Higgins <jeff@invalid.invalid> - 2015-07-01 18:25 -0400
    Re: Vertical Text - part 3 Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-01 23:09 +0000
      Re: Vertical Text - part 3 Jeff Higgins <jeff@invalid.invalid> - 2015-07-01 19:44 -0400
        Re: Vertical Text - part 3 Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-02 00:19 +0000
          Re: Vertical Text - part 3 Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-04 18:18 +0000
  Re: Vertical Text - part 3 Jeff Higgins <jeff@invalid.invalid> - 2015-07-02 09:09 -0400
    Re: Vertical Text - part 3 e.d.programmer@gmail.com - 2015-07-02 07:24 -0700
      Re: Vertical Text - part 3 Jeff Higgins <jeff@invalid.invalid> - 2015-07-02 10:36 -0400
        Re: Vertical Text - part 3 Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-02 18:38 +0000
          Re: Vertical Text - part 3 e.d.programmer@gmail.com - 2015-07-02 12:54 -0700
            Re: Vertical Text - part 3 Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-02 21:55 +0000
              Re: Vertical Text - part 3 Jeff Higgins <jeff@invalid.invalid> - 2015-07-02 18:46 -0400
                Re: Vertical Text - part 3 Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-03 10:38 +0000
                Re: Vertical Text - part 3 Eternal Hope <laughingspam99@gmail.com> - 2015-07-03 16:44 +0100
          Re: Vertical Text - part 3 Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2015-07-02 16:21 -0700
            Re: Vertical Text - part 3 Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2015-07-02 16:43 -0700
      Re: Vertical Text - part 3 Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-02 18:01 +0000
    Re: Vertical Text - part 3 Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-02 17:44 +0000
  Re: Vertical Text - part 3 Jeff Higgins <jeff@invalid.invalid> - 2015-07-03 08:20 -0400
    Re: Vertical Text - part 3 Jeff Higgins <jeff@invalid.invalid> - 2015-07-03 10:01 -0400

csiph-web