import javax.swing.*; import java.awt.*; import java.util.*; import java.io.*; import javax.swing.border.*; class PIMEntityPanel extends JPanel { static Color PIMNameColor = Color.BLACK; static Color PIMNameBackground = new Color(240,240,240); static Color PIMValueColor = Color.BLUE; static Color PIMValueBackground = Color.WHITE; PIMEntity e; public PIMEntityPanel(PIMEntity pe) { e = pe; setLayout(new BoxLayout(this,BoxLayout.Y_AXIS)); // setBorder(new EmptyBorder(3,3,3,3)); setBackground(Color.WHITE); populate(); } public static void main(String args[]) { try { PIMCollection pc = readCollection("pimdata"); Collection notes = pc.getNotes(); ArrayList a = new ArrayList(notes); JFrame f = new JFrame(); f.setSize(200,200); f.getContentPane().add(new PIMEntityPanel((PIMEntity)a.get(0))); f.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } void populate() { if (e instanceof PIMNote) { Note(); } } void Todo() { } void Contact() { } void Appointment() { } void Note() { PIMNote n = (PIMNote) e; JPanel top = new JPanel(new BorderLayout(3,3)); //JPanel j = new JPanel(new BorderLayout(3,3)); Box j = Box.createHorizontalBox(); // j.setBorder(BorderFactory.createRaisedBevelBorder()); j.setBackground(Color.GREEN); j.add( new FieldPanel("Priority:", n.getPriority(),FieldPanel.SMALL)); //,BorderLayout.WEST); j.add( new FieldPanel("Owner:", n.getOwner(),FieldPanel.SMALL)); // ,BorderLayout.EAST); j.add( Box.createHorizontalGlue()); top.add(j,BorderLayout.NORTH); JPanel note = new FieldPanel("Note:",n.getNote(),FieldPanel.LARGE); note.setBackground(Color.WHITE); top.add( note,BorderLayout.CENTER); add(top); } public static PIMCollection readCollection(String filename) throws IOException, ClassNotFoundException { PIMCollection c; ObjectInputStream ois = new ObjectInputStream( new FileInputStream(filename) ); c = (PIMCollection) ois.readObject(); ois.close(); return(c); } } /** FieldPanel holds a field name and value */ class FieldPanel extends JPanel { static final int SMALL = 0; static final int MEDIUM = 1; static final int LARGE = 2; static final Font SMALL_FONT = new Font("Serif",Font.PLAIN,12); static final Font MEDIUM_FONT = new Font("Serif",Font.PLAIN,14); static final Font LARGE_FONT = new Font("Serif",Font.BOLD,16); static final Font []fonts = { SMALL_FONT, MEDIUM_FONT, LARGE_FONT }; static Color PIMNameColor = Color.BLACK; static Color PIMNameBackground = new Color(240,240,240); static Color PIMValueColor = Color.BLUE; static Color PIMValueBackground = Color.WHITE; FieldPanel( String fName, String fValue, int size) { Box b = Box.createHorizontalBox(); b.setBorder(BorderFactory.createRaisedBevelBorder()); JLabel jName = new JLabel(fName); jName.setForeground(PIMNameColor); jName.setBackground(PIMNameBackground); jName.setFont(fonts[size]); JLabel jValue = new JLabel(fValue,JLabel.LEFT); jValue.setForeground(PIMValueColor); jValue.setBackground(PIMValueBackground); jValue.setFont(fonts[size]); b.add(jName); b.add(jValue); add(b); } }