Results 1 to 2 of 2
  1. #1
    AcousticBruce is offline Senior Member
    Join Date
    Dec 2010
    Location
    Indiana
    Posts
    202
    Rep Power
    5

    Default Guys Please take the time to look at this and understand.. I try my best to explain

    This is basically going to be a print preview on a panel in my program. This is basically after a user has entered manually what UNIT sizes they want, this is just an example of what it might display.

    I need this really about 60% of the size. Sure I can use Graphics2D to scale it down, but not when I add a Printable class and try to print everything is all off size.

    What I want to do is create a virtual JPanel that is a MAIN source of data. The actualy print preview will be scaled down around 60%. But the Printable will leave all the sizes in tact and pull from the MAIN source... so this would be a MAIN source.

    So basically this code will be a MAIN source that the actualy print preveiw will scale down to 60% or so and the Printable side will pull this info to print.


    Please let me know how I can be more clear. Also let me know if there is a better way to look at this.

    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.print.*;
    import java.awt.event.*;
    
    public class PrintGrid extends JFrame {
    
        Paper paper = new Paper();
    
        PrintGrid() {
        	super("Check out this grid panel");
        	setSize(700, 770);
        	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
        	add(paper);
    
        	setVisible(true);
    
        } // end PrintGrid constructor
    
    
    
        // **************************
        // ****** PAPER CLASS *******
        // **************************
        private class Paper extends JPanel {
    
        	final int PAPER_X = 672, PAPER_Y = 975, UNIT = 12, DPI = 72;
    		X1 x1a = new X1(), x1b = new X1(), x1c = new X1();
    		X2 x2a = new X2(), x2b = new X2(), x2c = new X2();
    		X3 x3a = new X3(), x3b = new X3(), x3c = new X3();
    
        	Paper() {
        		setPreferredSize(new Dimension(PAPER_X, PAPER_Y));
        		setBackground(Color.WHITE);
        		setLayout(new FlowLayout(FlowLayout.LEADING));
    
    			//Users will manually add different sizes to this sheet.
        		add(x1a);
        		add(x2a);
        		add(x3a);
        		add(x1b);
        		add(x1c);
        		add(x2b);
        		add(x3b);
        	}
    
    
        	// ******* Parent Class for GridUnits *******
        	abstract class GridUnit extends JPanel {
    
    			MouseListen ml = new MouseListen();
    			float alpha = 1.0f;
    
    			GridUnit() {
    				this.addMouseListener(ml);
    			}
        		public void paintComponent(Graphics g) {
        			super.paintComponent(g);
        			this.setBackground(Color.BLACK);
    
    				Graphics2D g2 = (Graphics2D) g;
    				g2.setComposite(makeComposite(alpha));
    
        			g.setColor(Color.WHITE);
        			g.drawRect(5, 5, this.getWidth()-10, this.getHeight()-10);
    
        			g.setColor(Color.darkGray);
        			g.fillRect(15, 15, this.getWidth()-30, this.getHeight()-30);
    
        		} // end paintComponent.
    
        		private AlphaComposite makeComposite(float alpha) {
        			int type = AlphaComposite.SRC_OVER;
         			return(AlphaComposite.getInstance(type, alpha));
    			}
    
        		void click() {
        			setVisible(false);
        		}
        		void entered() {
        			alpha = 0.8f;
        			repaint();
    
        		}
        		void exited() {
        			alpha = 1.0f;
        			repaint();
        		}
    
        		class MouseListen extends MouseAdapter {
        			public void mouseEntered(MouseEvent event) {
        				entered();
        			}
        			public void mouseExited(MouseEvent event) {
        				exited();
        			}
        			public void mousePressed(MouseEvent event) {
        				click();
        			}
        		}
    
        	} // end GridUnit class
    
        	class X1 extends GridUnit {
        		X1() {
        			setPreferredSize(new Dimension(UNIT*13, UNIT*18));
        		}
        	} // end X1 Class
    
        	class X2 extends GridUnit {
        		X2() {
        			setPreferredSize(new Dimension(UNIT*26, UNIT*18));
        		}
        	} // end X1 Class
    
        	class X3 extends GridUnit {
        		X3() {
        			setPreferredSize(new Dimension(UNIT*39, UNIT*18));
        		}
        	} // end X1 Class
    
        } // end Paper class.
    
    
    
        public static void main(String[] args) {
        	new PrintGrid();
        } // end main method.
    
    } //  end PrintGrid class.

  2. #2
    AcousticBruce is offline Senior Member
    Join Date
    Dec 2010
    Location
    Indiana
    Posts
    202
    Rep Power
    5

Similar Threads

  1. Replies: 3
    Last Post: 08-23-2011, 01:46 PM
  2. Replies: 3
    Last Post: 03-01-2011, 02:39 AM
  3. Replies: 0
    Last Post: 12-21-2010, 07:09 AM
  4. Replies: 2
    Last Post: 12-13-2010, 02:34 PM
  5. Replies: 3
    Last Post: 12-13-2010, 08:22 AM

Posting Permissions

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