view src/junotu/CardWidget.java @ 8:9d3256f86803

Functional card creation and search
author Fox
date Fri, 08 Apr 2022 11:48:17 +0200
parents 6e29262ee18c
children 587b69a38915
line wrap: on
line source

package junotu;

import java.awt.Font;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import javax.swing.BorderFactory;

import javax.swing.JPanel;

import java.awt.GridBagLayout;

import javax.swing.JLabel;
import javax.swing.JTextArea;

import junotu.Database.Card;

public class CardWidget extends JPanel {

    public long identifier;
    
    public CardWidget( Card card )
    {
	this.setLayout( new GridBagLayout() );

	identifier = card.identifier;
	JLabel title = new JLabel( card.title, JLabel.LEFT );
	JTextArea content = new JTextArea( card.content );

	title.setFont( new Font( "Monospaced", Font.BOLD, 16 ) );
	content.setFont( new Font( "Monospaced", Font.PLAIN, 12 ) );
	
	this.setMinimumSize( new Dimension( 96, 32 ) );
	this.setPreferredSize( new Dimension( 128, 128 ) );
	this.setMaximumSize( new Dimension( 1000000000, 128 ) );

	title.setMinimumSize( new Dimension( 32, 32 ) );

	this.setBorder( BorderFactory.createRaisedBevelBorder() );
	content.setEditable( false );
	content.setLineWrap( true );
	content.setWrapStyleWord( true );
	content.setOpaque( false );
	
	GridBagConstraints constraints = new GridBagConstraints();
	constraints.anchor = GridBagConstraints.WEST;
	constraints.fill = GridBagConstraints.HORIZONTAL;
	constraints.weightx = 1.0;
	
	this.add( title, constraints );
	constraints.anchor = GridBagConstraints.NORTHWEST;
	constraints.gridx++;
	constraints.fill = GridBagConstraints.BOTH;
	constraints.weighty = 0.5;
	this.add( content, constraints );
	
    }
}