diff --git a/.gitignore b/.gitignore index 0f182a0..682dc24 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ -*.class - -# Package Files # -*.jar -*.war -*.ear +.DS_Store +/.classpath +/.project +/.settings/ +/nbactions.xml +/target/ diff --git a/README.md b/README.md index 8b13789..12a3398 100644 --- a/README.md +++ b/README.md @@ -1 +1,74 @@ +This is a minimal Maven project implementing an ImageJ 1.x plugin +It is intended as an ideal starting point to develop new ImageJ 1.x plugins +in an IDE of your choice. You can even collaborate with developers using a +different IDE than you. + +In [Eclipse](http://eclipse.org), for example, it is as simple as +_File>Import...>Existing Maven Project_ + +In [Netbeans](http://netbeans.org), it is even simpler: _File>Open_ +Project. The same works in [IntelliJ](http://jetbrains.net). + +If [jEdit](http://jedit.org) is your preferred IDE, you will need the [Maven +Plugin](http://plugins.jedit.org/plugins/?MavenPlugin). + +Die-hard command-line developers can use Maven directly by calling _mvn_ +in the project root. + +However you build the project, in the end you will have the ```.jar``` file +(called *artifact* in Maven speak) in the _target/_ subdirectory. + +To copy the artifact into the correct place, you can call ```mvn +-Dimagej.app.directory=/path/to/Fiji.app/```. This will not only copy your +artifact, but also all the dependencies. Restart your ImageJ or call +*Help>Refresh Menus* to see your plugin in the menus. + +Developing plugins in an IDE is convenient, especially for debugging. To +that end, the plugin contains a _main()_ method which sets the _plugins.dir_ +system property (so that the plugin is added to the Plugins menu), starts +ImageJ, loads an image and runs the plugin. See also +[this page](fiji.sc/Debugging#Debugging_plugins_in_an_IDE_.28Netbeans.2C_IntelliJ.2C_Eclipse.2C_etc.29) +for information how Fiji makes it easier to debug in IDEs. + +Since this project is intended as a starting point for your own +developments, it is in the public domain. + +How to use this project as a starting point +=========================================== + +Either + +* ```git clone git://github.com/imagej/minimal-ij1-plugin```, or +* unpack https://github.com/imagej/minimal-ij1-plugin/archive/master.zip + +Then: + +1. Edit the ```pom.xml``` file. Every entry should be pretty self-explanatory. + In particular, change + 1. the *artifactId* (and optionally also *groupId*) + 2. the *version* (note that you typically want to use a version number + ending in *-SNAPSHOT* to mark it as a work in progress rather than a + final version) + 3. the *dependencies* (read how to specify the correct + *groupId/artifactId/version* triplet + [here](http://fiji.sc/Maven#How_to_find_a_dependency.27s_groupId.2FartifactId.2Fversion_.28GAV.29.3F)) + 4. the *developer* information + 5. the *scm* information +2. Remove the ```Process_Pixels.java``` file and add your own ```.java``` files + to ```src/main/java//``` (if you need supporting files -- like icons + -- in the resulting ```.jar``` file, put them into ```src/main/resources/```) +3. Edit ```src/main/resources/plugins.config``` +4. Replace the contents of ```README.md``` with information about your project. + +If you cloned the ```minimal-ij1-plugin``` repository, you probably want to +publish the result in your own repository: + +1. Call ```git status``` to verify .gitignore lists all the files (or file + patterns) that should be ignored +2. Call ```git add .``` and ```git add -u``` to stage the current files for + commit +3. Call ```git commit``` or ```git gui``` to commit the changes +4. [Create a new GitHub repository](https://github.com/new) +5. ```git remote set-url origin git@github.com:/``` +6. ```git push origin HEAD``` diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..1d07e32 --- /dev/null +++ b/pom.xml @@ -0,0 +1,98 @@ + + + 4.0.0 + + + org.scijava + pom-scijava + 1.51 + + + my.postcard + A_Postcard + 0.1.0 + + A_Postcard + Postcard gereration + + + + net.imagej + ij + ${imagej1.version} + + + org.swinglabs + swing-layout + 1.0.3 + + + + + + + ${project.build.sourceDirectory} + + + + + ${project.build.testSourceDirectory} + + + + + org.codehaus.mojo + exec-maven-plugin + + + + java + + + + + A_Postcard + + + + + + + + gaiag + Christopher Coulon + chris@gaiag.net + http://gaiag.net + The GAIA Group + http://gaiag.net + + architect + developer + + -7 + + + + + + + imagej.releases + http://maven.imagej.net/content/repositories/releases + + + imagej.snapshots + http://maven.imagej.net/content/repositories/snapshots + + + + + scm:git:git://github.com/imagej/minimal-ij1-plugin + scm:git:git@github.com:imagej/minimal-ij1-plugin + HEAD + https://github.com/imagej/minimal-ij1-plugin + + + diff --git a/src/main/java/AAPC_Var.java b/src/main/java/AAPC_Var.java new file mode 100644 index 0000000..280ff21 --- /dev/null +++ b/src/main/java/AAPC_Var.java @@ -0,0 +1,236 @@ +import ij.ImagePlus; +import ij.gui.Roi; + + +/** + * Copyright Jun 30, 2012 The GAIA Group + * http://gaiag.net + */ +public class AAPC_Var { + + private static PostCard pc; + private static ChooseCardTemplate cc; + private static YourImage yi; + private static FinalizePC fpc; + private static PickSubject ps; + private static WandFrame wf; + private static FinishingTouches ft; + private static Cut_Paste cp; + private static OutlineSubject os; + + + private static ImagePlus imp, img; + + private static Roi roi; + + private static int language, + pcX, pcY, + backKey; + private static double pcW, pcH; + + private static String path; + private static Boolean horizontal; + + static void putChooseCardTemplate(ChooseCardTemplate c) { + cc = c; + } + + static void putYourImage(YourImage y) { + yi = y; + } + + static void putFinalizePC(FinalizePC f) { + fpc = f; + } + + static void putCutPaste(Cut_Paste c) { + cp = c; + } + + static void putPickSubject(PickSubject p) { + ps = p; + } + + static void setBackKey(int bk) { + backKey = bk; + } + + static int getBackKey() { + return backKey; + } + + AAPC_Var(PostCard p) { + + pc = p; + + } + + public static PostCard getPostCard() { + return pc; + } + + public static void showPostCard() { + pc.setVisible(true); + } + + public static void hidePostCard() { + pc.setVisible(false); + } + + public static void showChooseCard() { + cc.setVisible(true); + } + + public static void hideChooseCard() { + cc.setVisible(false); + } + + public static void showYourImage() { + yi.setVisible(true); + } + + public static void hideYourImage() { + yi.setVisible(false); + } + + public static void showCutPaste() { + cp.setVisible(true); + } + + public static void hideCutPaste() { + cp.setVisible(false); + } + + static void showFinalize() { + fpc.setVisible(true); + } + + static void hideFinalize() { + fpc.setVisible(false); + } + + static void showPicSubject() { + ps.setVisible(true); + } + + static void hidePicSubject() { + ps.setVisible(false); + } + + static void setOutlineSubject(OutlineSubject o) { + os = o; + } + + static void showOutlineSubject() { + os.setVisible(true); + } + + static void hideOutlineSubject() { + os.setVisible(false); + } + + static void setWandFrame(WandFrame w) { + wf = w; + } + + static void showWandFrame() { + wf.setVisible(true); + } + + static void hideWandFrame() { + wf.setVisible(false); + } + + static void setFinishingTouches(FinishingTouches f) { + ft = f; + } + + static void showFinishingTouches() { + ft.setVisible(true); + } + + static void hideFinishingTouches() { + ft.setVisible(false); + } + + static void putImage(ImagePlus ip) { + imp = ip; + } + + static ImagePlus getImage() { + return imp; + } + + static void putSubject(ImagePlus s) { + img = s; + } + + static ImagePlus getSubject() { + return img; + } + + static void setROI(Roi r) { + roi = r; + } + + static Roi getROI() { + return roi; + } + + static void setLanguage(int lang) { + language = lang; + } + + static int getLanguage() { + return language; + } + + public static void setPath(String p) { + path = p; + } + + public static String getPath() { + return path; + } + + public static void setOrientation(Boolean orien) { + horizontal = orien; + } + + public static Boolean getOrientation() { + return horizontal; + } + + public static void setPCX(int x) { + pcX = x; + } + + public static int getPCX() { + return pcX; + } + + public static void setPCY(int y) { + pcY = y; + } + + public static int getPCY() { + return pcY; + } + + static void setPCW(double pW) { + pcW = pW; + } + + public static double getPCW() { + return pcW; + } + + static void setPCH(double pH) { + pcH = pH; + } + + public static double getPCH() { + return pcH; + } + +} diff --git a/src/main/java/A_Postcard.java b/src/main/java/A_Postcard.java new file mode 100644 index 0000000..3716040 --- /dev/null +++ b/src/main/java/A_Postcard.java @@ -0,0 +1,37 @@ + +import ij.IJ; +import ij.plugin.PlugIn; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author chris + */ +public class A_Postcard implements PlugIn { + + @Override + public void run(String s) { + + s = "process"; +// s = "aaa"; +// s = "iroi"; + + if (s.equals("process")) { + + PostCard pc = new PostCard(); + + AAPC_Var aapc = new AAPC_Var(pc); + + aapc.showPostCard(); + } + } + + public static void main(final String... args ) { + new ij.ImageJ(); + new A_Postcard().run(""); + } +} diff --git a/src/main/java/ChooseCardTemplate.java b/src/main/java/ChooseCardTemplate.java new file mode 100644 index 0000000..f5b5337 --- /dev/null +++ b/src/main/java/ChooseCardTemplate.java @@ -0,0 +1,1168 @@ +import ij.IJ; +import ij.ImagePlus; +import ij.io.OpenDialog; + +/* + * ChooseCardTemplate.java + * + * Created on Jun 16, 2012, 5:31:50 PM + */ +/** + * Copyright Jun 7, 2012 The GAIA Group + * http://gaiag.net + * + * @author chris + */ + +public class ChooseCardTemplate extends javax.swing.JFrame { + + /** Creates new form ChooseCardTemplate */ + public ChooseCardTemplate() { + initComponents(); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // + private void initComponents() { + java.awt.GridBagConstraints gridBagConstraints; + + ChoiceLabel = new javax.swing.JLabel(); + OnePhotoPanel = new javax.swing.JPanel(); + OnePhotoLabel = new javax.swing.JLabel(); + horizontal1Label = new javax.swing.JLabel(); + vertical1Label = new javax.swing.JLabel(); + twoPhotoPanel = new javax.swing.JPanel(); + TwoPhotoLabel = new javax.swing.JLabel(); + vertical2Label = new javax.swing.JLabel(); + horizontal2Label = new javax.swing.JLabel(); + threePhotoPanel = new javax.swing.JPanel(); + ThreePhotoLabel = new javax.swing.JLabel(); + vertical1horizontal2Label = new javax.swing.JLabel(); + vertical2horizontal1Label = new javax.swing.JLabel(); + fourPhotoPanel = new javax.swing.JPanel(); + FourPhotoLabel = new javax.swing.JLabel(); + horizontal4Label = new javax.swing.JLabel(); + vertical4Label = new javax.swing.JLabel(); + HomePanel = new javax.swing.JPanel(); + HomeLabel = new javax.swing.JLabel(); + dataDeviceLabel = new javax.swing.JLabel(); + egLabel = new javax.swing.JLabel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); + setBackground(new java.awt.Color(31, 73, 125)); + setMaximumSize(new java.awt.Dimension(1920, 1080)); + setPreferredSize(new java.awt.Dimension(1920, 1080)); + getContentPane().setLayout(new java.awt.GridBagLayout()); + + ChoiceLabel.setBackground(new java.awt.Color(79, 129, 189)); + ChoiceLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 36)); // NOI18N + ChoiceLabel.setForeground(new java.awt.Color(230, 224, 236)); + ChoiceLabel.setText("Chose a template:"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.gridwidth = 2; + gridBagConstraints.gridheight = 3; + gridBagConstraints.ipadx = 71; + gridBagConstraints.ipady = 34; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 0); + getContentPane().add(ChoiceLabel, gridBagConstraints); + + OnePhotoPanel.setBackground(new java.awt.Color(79, 129, 189)); + OnePhotoPanel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); + + OnePhotoLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 24)); // NOI18N + OnePhotoLabel.setForeground(new java.awt.Color(230, 224, 236)); + OnePhotoLabel.setText("One photo"); + + horizontal1Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pcH1.jpg"))); // NOI18N + horizontal1Label.setText("jLabel1"); + horizontal1Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + horizontal1Clicked(evt); + } + }); + + vertical1Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pcV1.jpg"))); // NOI18N + vertical1Label.setText("jLabel1"); + vertical1Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + vertical1Clicked(evt); + } + }); + + org.jdesktop.layout.GroupLayout OnePhotoPanelLayout = new org.jdesktop.layout.GroupLayout(OnePhotoPanel); + OnePhotoPanel.setLayout(OnePhotoPanelLayout); + OnePhotoPanelLayout.setHorizontalGroup( + OnePhotoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(OnePhotoPanelLayout.createSequentialGroup() + .add(OnePhotoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(OnePhotoPanelLayout.createSequentialGroup() + .addContainerGap() + .add(horizontal1Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 182, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(18, 18, 18) + .add(vertical1Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 124, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(OnePhotoPanelLayout.createSequentialGroup() + .add(10, 10, 10) + .add(OnePhotoLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 200, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + OnePhotoPanelLayout.setVerticalGroup( + OnePhotoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(OnePhotoPanelLayout.createSequentialGroup() + .add(OnePhotoLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(OnePhotoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(vertical1Label) + .add(horizontal1Label)) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 3; + gridBagConstraints.gridwidth = 5; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new java.awt.Insets(6, 60, 0, 0); + getContentPane().add(OnePhotoPanel, gridBagConstraints); + + twoPhotoPanel.setBackground(new java.awt.Color(79, 129, 189)); + twoPhotoPanel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); + + TwoPhotoLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 24)); // NOI18N + TwoPhotoLabel.setForeground(new java.awt.Color(230, 224, 236)); + TwoPhotoLabel.setText("Two photos"); + + vertical2Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pcV2.jpg"))); // NOI18N + vertical2Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + vertical2Clicked(evt); + } + }); + + horizontal2Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pcH2.jpg"))); // NOI18N + horizontal2Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + horizontal2Clicked(evt); + } + }); + + org.jdesktop.layout.GroupLayout twoPhotoPanelLayout = new org.jdesktop.layout.GroupLayout(twoPhotoPanel); + twoPhotoPanel.setLayout(twoPhotoPanelLayout); + twoPhotoPanelLayout.setHorizontalGroup( + twoPhotoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(twoPhotoPanelLayout.createSequentialGroup() + .add(twoPhotoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(twoPhotoPanelLayout.createSequentialGroup() + .add(10, 10, 10) + .add(TwoPhotoLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 200, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(twoPhotoPanelLayout.createSequentialGroup() + .addContainerGap() + .add(vertical2Label) + .add(18, 18, 18) + .add(horizontal2Label))) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + twoPhotoPanelLayout.setVerticalGroup( + twoPhotoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(twoPhotoPanelLayout.createSequentialGroup() + .add(TwoPhotoLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(twoPhotoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(horizontal2Label) + .add(vertical2Label)) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 7; + gridBagConstraints.gridy = 3; + gridBagConstraints.gridwidth = 12; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new java.awt.Insets(6, 24, 0, 6); + getContentPane().add(twoPhotoPanel, gridBagConstraints); + + threePhotoPanel.setBackground(new java.awt.Color(79, 129, 189)); + threePhotoPanel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); + + ThreePhotoLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 24)); // NOI18N + ThreePhotoLabel.setForeground(new java.awt.Color(230, 224, 236)); + ThreePhotoLabel.setText("Three photos"); + + vertical1horizontal2Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pcV1H2.jpg"))); // NOI18N + vertical1horizontal2Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + vertical1Horizontal2Clicked(evt); + } + }); + + vertical2horizontal1Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pcV2H1.jpg"))); // NOI18N + vertical2horizontal1Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + vertical2horizontal1Clicked(evt); + } + }); + + org.jdesktop.layout.GroupLayout threePhotoPanelLayout = new org.jdesktop.layout.GroupLayout(threePhotoPanel); + threePhotoPanel.setLayout(threePhotoPanelLayout); + threePhotoPanelLayout.setHorizontalGroup( + threePhotoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(threePhotoPanelLayout.createSequentialGroup() + .add(threePhotoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(threePhotoPanelLayout.createSequentialGroup() + .add(10, 10, 10) + .add(ThreePhotoLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 200, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(threePhotoPanelLayout.createSequentialGroup() + .addContainerGap() + .add(vertical1horizontal2Label) + .add(18, 18, 18) + .add(vertical2horizontal1Label))) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + threePhotoPanelLayout.setVerticalGroup( + threePhotoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(threePhotoPanelLayout.createSequentialGroup() + .add(ThreePhotoLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(threePhotoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(vertical2horizontal1Label) + .add(vertical1horizontal2Label)) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 4; + gridBagConstraints.gridwidth = 3; + gridBagConstraints.gridheight = 2; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new java.awt.Insets(30, 60, 0, 0); + getContentPane().add(threePhotoPanel, gridBagConstraints); + + fourPhotoPanel.setBackground(new java.awt.Color(79, 129, 189)); + fourPhotoPanel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); + + FourPhotoLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 24)); // NOI18N + FourPhotoLabel.setForeground(new java.awt.Color(230, 224, 236)); + FourPhotoLabel.setText("Four photos"); + + horizontal4Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pcH4.jpg"))); // NOI18N + horizontal4Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + horizontal4Clicked(evt); + } + }); + + vertical4Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pcV4.jpg"))); // NOI18N + vertical4Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + vertical4Clicked(evt); + } + }); + + org.jdesktop.layout.GroupLayout fourPhotoPanelLayout = new org.jdesktop.layout.GroupLayout(fourPhotoPanel); + fourPhotoPanel.setLayout(fourPhotoPanelLayout); + fourPhotoPanelLayout.setHorizontalGroup( + fourPhotoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(fourPhotoPanelLayout.createSequentialGroup() + .add(fourPhotoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(fourPhotoPanelLayout.createSequentialGroup() + .add(10, 10, 10) + .add(FourPhotoLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 200, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(fourPhotoPanelLayout.createSequentialGroup() + .addContainerGap() + .add(horizontal4Label) + .add(18, 18, 18) + .add(vertical4Label))) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + fourPhotoPanelLayout.setVerticalGroup( + fourPhotoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(fourPhotoPanelLayout.createSequentialGroup() + .add(FourPhotoLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(fourPhotoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(vertical4Label) + .add(horizontal4Label)) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 7; + gridBagConstraints.gridy = 4; + gridBagConstraints.gridwidth = 12; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new java.awt.Insets(30, 24, 0, 6); + getContentPane().add(fourPhotoPanel, gridBagConstraints); + + HomePanel.setBackground(new java.awt.Color(79, 129, 189)); + HomePanel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); + HomePanel.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + HomeClicked(evt); + } + }); + + HomeLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 24)); // NOI18N + HomeLabel.setForeground(new java.awt.Color(230, 224, 236)); + HomeLabel.setText("Home"); + + org.jdesktop.layout.GroupLayout HomePanelLayout = new org.jdesktop.layout.GroupLayout(HomePanel); + HomePanel.setLayout(HomePanelLayout); + HomePanelLayout.setHorizontalGroup( + HomePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, HomePanelLayout.createSequentialGroup() + .addContainerGap(176, Short.MAX_VALUE) + .add(HomeLabel) + .addContainerGap()) + ); + HomePanelLayout.setVerticalGroup( + HomePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(HomePanelLayout.createSequentialGroup() + .addContainerGap() + .add(HomeLabel) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 6; + gridBagConstraints.ipadx = 147; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new java.awt.Insets(18, 60, 15, 0); + getContentPane().add(HomePanel, gridBagConstraints); + + dataDeviceLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 18)); // NOI18N + dataDeviceLabel.setForeground(new java.awt.Color(230, 224, 236)); + dataDeviceLabel.setText("Please connect your data device"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 0; + gridBagConstraints.gridwidth = 11; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new java.awt.Insets(16, 6, 0, 0); + getContentPane().add(dataDeviceLabel, gridBagConstraints); + + egLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 18)); // NOI18N + egLabel.setForeground(new java.awt.Color(230, 224, 236)); + egLabel.setText("(e.g., USB-stick, SB card, etc.)"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 1; + gridBagConstraints.gridwidth = 6; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 0); + getContentPane().add(egLabel, gridBagConstraints); + + pack(); + }// + + private void horizontal1Clicked(java.awt.event.MouseEvent evt) { + + ImagePlus h1 = null; + int type = 0; + h1 = openImageSet(type, h1); + + horizontal = true; + + IJ.run(h1, "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel"); + + h1 = setScale(h1, horizonWidth, horizonHeight); + + setToPostCard(h1, 0); + + } + + private void HomeClicked(java.awt.event.MouseEvent evt) { + + AAPC_Var.showPostCard(); + AAPC_Var.hideChooseCard(); + + } + + private void vertical1Clicked(java.awt.event.MouseEvent evt) { + + ImagePlus v1 = null; + int type = 0; + v1 = openImageSet(type, v1); + + horizontal = false; + + IJ.run(v1, "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel"); + + v1 = setScale(v1, verticalWidth, verticalHeight); + + setToPostCard(v1, 1); + + } + + private void vertical2Clicked(java.awt.event.MouseEvent evt) { + + ImagePlus v1 = null; + int type = 1; + v1 = openImageSet(type, v1); + + horizontal = true; + + IJ.run(v1, "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel"); + + int pcW1 = v1.getWidth(); + int pcH1 = v1.getHeight(); + + ImagePlus v2 = null; + type = 2; + v2 = openImageSet(type, v2); + + IJ.run(v2, "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel"); + + int pcW2 = v2.getWidth(); + int pcH2 = v2.getHeight(); + + setToPostCardV(v1, v2, pcW1, pcH1, pcW2, pcH2, + horizonWidth, horizonHeight, pcHW, pcHH); + + } + + private void horizontal2Clicked(java.awt.event.MouseEvent evt) { + + ImagePlus h1 = null; + int type = 1; + h1 = openImageSet(type, h1); + + horizontal = false; + + IJ.run(h1, "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel"); + + int pcW1 = h1.getWidth(); + int pcH1 = h1.getHeight(); + + ImagePlus h2 = null; + type = 2; + h2 = openImageSet(type, h2); + + IJ.run(h2, "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel"); + + int pcW2 = h2.getWidth(); + int pcH2 = h2.getHeight(); + + setToPostCardH(h1, h2, pcW1, pcH1, pcW2, pcH2); + + } + + private void vertical1Horizontal2Clicked(java.awt.event.MouseEvent evt) { + + ImagePlus v1 = null; + int type = 1; + v1 = openImageSet(type, v1); + + horizontal = true; + + IJ.run(v1, "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel"); + + ImagePlus h1 = null; + type = 2; + h1 = openImageSet(type, h1); + + IJ.run(h1, "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel"); + + ImagePlus h2 = null; + type = 3; + h2 = openImageSet(type, h2); + + IJ.run(h2, "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel"); + + setToPostCardV1H2(v1, h1, h2); + + } + + private void vertical2horizontal1Clicked(java.awt.event.MouseEvent evt) { + + ImagePlus v1 = null; + int type = 1; + v1 = openImageSet(type, v1); + + horizontal = false; + + IJ.run(v1, "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel"); + + ImagePlus v2 = null; + type = 2; + v2 = openImageSet(type, v2); + + IJ.run(v2, "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel"); + + ImagePlus h1 = null; + type = 3; + h1 = openImageSet(type, h1); + + IJ.run(h1, "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel"); + + setToPostCardV2H1(v1, v2, h1); + + } + + private void horizontal4Clicked(java.awt.event.MouseEvent evt) { + + ImagePlus h1 = null; + int type = 1; + h1 = openImageSet(type, h1); + + horizontal = true; + + IJ.run(h1, "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel"); + + int pcW1 = h1.getWidth(); + int pcH1 = h1.getHeight(); + + ImagePlus h2 = null; + type = 2; + h2 = openImageSet(type, h2); + + IJ.run(h2, "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel"); + + int pcW2 = h2.getWidth(); + int pcH2 = h2.getHeight(); + + ImagePlus h3 = null; + type = 3; + h3 = openImageSet(type, h3); + + IJ.run(h3, "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel"); + + int pcW3 = h3.getWidth(); + int pcH3 = h3.getHeight(); + + ImagePlus h4 = null; + type = 4; + h4 = openImageSet(type, h4); + + IJ.run(h4, "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel"); + + int pcW4 = h4.getWidth(); + int pcH4 = h4.getHeight(); + + setToPostCardH4(h1, h2, h3, h4); + + } + + private void vertical4Clicked(java.awt.event.MouseEvent evt) { + + ImagePlus v1 = null; + int type = 1; + v1 = openImageSet(type, v1); + + horizontal = false; + + IJ.run(v1, "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel"); + + ImagePlus v2 = null; + type = 2; + v2 = openImageSet(type, v2); + + IJ.run(v2, "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel"); + + ImagePlus v3 = null; + type = 3; + v3 = openImageSet(type, v3); + + IJ.run(v3, "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel"); + + ImagePlus v4 = null; + type = 4; + v4 = openImageSet(type, v4); + + IJ.run(v4, "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel"); + + setToPostCardV4(v1, v2, v3, v4); + + } + + private ImagePlus openImageSet(int type, ImagePlus ip) { + + String s = "Select the Postcard Image"; + + switch (type) { + + case 0: + s = "Select the Postcard Image"; + break; + + case 1: + s = "Select the first Postcard Image"; + break; + + case 2: + s = "Select the second Postcard Image"; + break; + + case 3: + s = "Select the third Postcard Image"; + break; + + case 4: + s = "Select the forth Postcard Image"; + break; + } + + OpenDialog opendialog = new OpenDialog(s, ""); + + resultsPath = IJ.getDirectory("home"); + String s2 = opendialog.getDirectory(); + String s3 = opendialog.getFileName(); + + ip = IJ.openImage(s2 + s3); + + return ip; + + } + + private void setToPostCard(ImagePlus ip, int key) { + + int pcW = 0, pcH = 0, Width = 0, Height = 0; + + if (key == 0) { + pcW = 1800; + pcH = 1200; + Width = 1750; + Height = 1150; + + } else { + pcW = 1200; + pcH = 1800; + Width = 1150; + Height = 1750; + + } + + ImagePlus pc = IJ.createImage("PostCard", "RGB White", pcW, pcH, 1); + IJ.run(ip, "Copy", ""); + pc.setRoi(25, 25, Width, Height); + IJ.run(pc, "Paste", ""); + IJ.run("Colors...", "foreground=black background=white selection=yellow"); + pc.setRoi(25, 25, Width, Height); + IJ.run(pc, "Clear Outside", ""); + IJ.run(pc, "Select None", ""); + pc.show(); + storeImage(pc); + + } + + private void setToPostCardV(ImagePlus v1, ImagePlus v2, + int pcW1, int pcH1, int pcW2, int pcH2, + int vWidth, int vHeight, int pcVW, int pcVH) { + + double halfw = (double) (vWidth / 2) - 10; + double halfpc = (double) pcVW / 2; + double im1ratio = (double) pcW1 / pcH1; + double im2ratio = (double) pcW2 / pcH2; + double pcratio = (double) halfw / vHeight; + + v1 = verticalScale(v1, halfw, vHeight, pcW1, pcH1, im1ratio, pcratio); + + v2 = verticalScale(v2, halfw, vHeight, pcW2, pcH2, im2ratio, pcratio); + + ImagePlus pc = IJ.createImage("PostCard", "RGB White", pcVW, pcVH, 1); + IJ.run(v1, "Copy", ""); + pc.setRoi(25, 25, (int) halfw, vHeight); + IJ.run(pc, "Paste", ""); + IJ.run("Colors...", "foreground=black background=white selection=yellow"); + + IJ.run(v2, "Copy", ""); + pc.setRoi((int) halfpc + 10, 25, (int) halfw, vHeight); + IJ.run(pc, "Paste", ""); + + IJ.run(pc, "Select None", ""); + pc.show(); + storeImage(pc); + + } + + private ImagePlus verticalScale(ImagePlus v1, double halfw, int vHeight, + int pcW, int pcH, double imratio, double pcratio) { + + if (imratio == pcratio) { + + int hw = (int) halfw; + int hh = (int) vHeight; + + scaleImage(v1, hw, hh); + + } else if (imratio > pcratio) { + + double imh = (double) vHeight; + double imw = (double) (vHeight * pcW) / pcH; + + int hw = (int) imw; + int hh = (int) imh; + + scaleImage(v1, hw, hh); + + cropImage(v1, halfw, vHeight); + + } else if (imratio < pcratio) { + + double imw = (double) halfw; + double imh = (double) (halfw * pcH) / pcW; + + int hw = (int) imw; + int hh = (int) imh; + + scaleImage(v1, hw, hh); + + cropImage(v1, halfw, vHeight); + + } + + return v1; + } + + private void setToPostCardH(ImagePlus h1, ImagePlus h2, + int pcW1, int pcH1, int pcW2, int pcH2) { + + double halfpc = (double) pcVH / 2; + + h1 = setScale(h1, verticalWidth, halfVheight); + + h2 = setScale(h2, verticalWidth, halfVheight); + + ImagePlus pc = IJ.createImage("PostCard", "RGB White", pcVW, pcVH, 1); + IJ.run(h1, "Copy", ""); + pc.setRoi(25, 25, verticalWidth, halfVheight); + IJ.run(pc, "Paste", ""); + IJ.run("Colors...", "foreground=black background=white selection=yellow"); + + IJ.run(h2, "Copy", ""); + + int n1 = (int) halfpc + 5; + pc.setRoi(25, n1, verticalWidth, halfVheight); + IJ.run(pc, "Paste", ""); + + IJ.run(pc, "Select None", ""); + pc.show(); + storeImage(pc); + + } + + private void setToPostCardV1H2(ImagePlus v1, ImagePlus h1, ImagePlus h2) { + + double halfHpc = (double) pcHW / 2; + double halfVpc = (double) pcHH / 2; + + v1 = setScale(v1, halfHwidth, horizonHeight); + + h1 = setScale(h1, halfHwidth, halfHheight); + + h2 = setScale(h2, halfHwidth, halfHheight); + + ImagePlus pc = IJ.createImage("PostCard", "RGB White", pcHW, pcHH, 1); + IJ.run(v1, "Copy", ""); + pc.setRoi(25, 25, halfHwidth, horizonHeight); + IJ.run(pc, "Paste", ""); + + IJ.run(h1, "Copy", ""); + + int n1 = (int) halfHpc + 5; + pc.setRoi(n1, 25, halfHwidth, halfHheight); + IJ.run(pc, "Paste", ""); + + IJ.run(h2, "Copy", ""); + + int n2 = (int) (halfVpc + 5); + pc.setRoi(n1, n2, halfHwidth, halfHheight); + IJ.run(pc, "Paste", ""); + + IJ.run(pc, "Select None", ""); + pc.show(); + storeImage(pc); + + } + + private void setToPostCardV2H1(ImagePlus v1, ImagePlus v2, ImagePlus h1) { + + double halfHpc = (double) pcVW / 2; + double halfVpc = (double) pcVH / 2; + + v1 = setScale(v1, halfVwidth, halfVheight); + + v2 = setScale(v2, halfVwidth, halfVheight); + + h1 = setScale(h1, verticalWidth, halfVheight); + + ImagePlus pc = IJ.createImage("PostCard", "RGB White", pcVW, pcVH, 1); + IJ.run(v1, "Copy", ""); + pc.setRoi(25, 25, halfVwidth, halfVheight); + IJ.run(pc, "Paste", ""); + + IJ.run(v2, "Copy", ""); + + int n1 = (int) halfHpc + 5; + pc.setRoi(n1, 25, halfVwidth, halfVheight); + IJ.run(pc, "Paste", ""); + + IJ.run(h1, "Copy", ""); + + int n2 = (int) (halfVpc + 5); + pc.setRoi(25, n2, verticalWidth, halfVheight); + IJ.run(pc, "Paste", ""); + + IJ.run(pc, "Select None", ""); + pc.show(); + storeImage(pc); + + } + + private void setToPostCardH4(ImagePlus h1, ImagePlus h2, + ImagePlus h3, ImagePlus h4) { + + double halfHpc = (double) pcHW / 2; + double halfVpc = (double) pcHH / 2; + + h1 = setScale(h1, halfHwidth, halfHheight); + + h2 = setScale(h2, halfHwidth, halfHheight); + + h3 = setScale(h3, halfHwidth, halfHheight); + + h4 = setScale(h4, halfHwidth, halfHheight); + + ImagePlus pc = IJ.createImage("PostCard", "RGB White", pcHW, pcHH, 1); + IJ.run(h1, "Copy", ""); + pc.setRoi(25, 25, halfHwidth, halfHheight); + IJ.run(pc, "Paste", ""); + + IJ.run(h2, "Copy", ""); + + int n1 = (int) halfHpc + 5; + pc.setRoi(n1, 25, halfHwidth, halfHheight); + IJ.run(pc, "Paste", ""); + + IJ.run(h3, "Copy", ""); + + int n2 = (int) (halfVpc + 5); + pc.setRoi(25, n2, halfHwidth, halfHheight); + IJ.run(pc, "Paste", ""); + + IJ.run(h4, "Copy", ""); + + pc.setRoi(n1, n2, halfHwidth, halfHheight); + IJ.run(pc, "Paste", ""); + + IJ.run(pc, "Select None", ""); + pc.show(); + storeImage(pc); + + } + + private void setToPostCardV4(ImagePlus v1, ImagePlus v2, + ImagePlus v3, ImagePlus v4) { + + double halfHpc = (double) pcVW / 2; + double halfVpc = (double) pcVH / 2; + + v1 = setScale(v1, halfVwidth, halfVheight); + + v2 = setScale(v2, halfVwidth, halfVheight); + + v3 = setScale(v3, halfVwidth, halfVheight); + + v4 = setScale(v4, halfVwidth, halfVheight); + + ImagePlus pc = IJ.createImage("PostCard", "RGB White", pcVW, pcVH, 1); + IJ.run(v1, "Copy", ""); + pc.setRoi(25, 25, halfVwidth, halfVheight); + IJ.run(pc, "Paste", ""); + + IJ.run(v2, "Copy", ""); + + int n1 = (int) halfHpc + 5; + pc.setRoi(n1, 25, halfVwidth, halfVheight); + IJ.run(pc, "Paste", ""); + + IJ.run(v3, "Copy", ""); + + int n2 = (int) (halfVpc + 5); + pc.setRoi(25, n2, halfVwidth, halfVheight); + IJ.run(pc, "Paste", ""); + + IJ.run(v4, "Copy", ""); + + pc.setRoi(n1, n2, halfVwidth, halfVheight); + IJ.run(pc, "Paste", ""); + + IJ.run(pc, "Select None", ""); + pc.show(); + storeImage(pc); + + } + + private ImagePlus setScale(ImagePlus ip1, + int setW, int setH) { + + int pcW = ip1.getWidth(); + int pcH = ip1.getHeight(); + double imw = setW; + double imh = setH; + double imratio = (double) pcW / pcH; + double pcratio = (double) setW / setH; + + if (imratio > pcratio) { + + imw = (double) (setH * pcW) / pcH; + + } else { + + imh = (double) (setW * pcH) / pcW; + + } + + int iw = (int) imw; + int ih = (int) imh; + + scaleImage(ip1, iw, ih); + + cropImage(ip1, setW, setH); + + return ip1; + + } + + private void scaleImage(ImagePlus ip, int iw, int ih) { + + IJ.run(ip, "Size...", "width=" + iw + " height=" + ih + + " constrain average interpolation=Bilinear"); + + if (ip.getWidth() < iw || ip.getHeight() < ih) { + IJ.run(ip, "Size...", "width=" + iw + + " height=" + ih + + " average interpolation=Bilinear"); + } + + } + + private void cropImage(ImagePlus ip, double w, int h) { + + ip.setRoi(0, 0, (int) w, h); + + IJ.run(ip, "Crop", ""); + + } + + private void storeImage(ImagePlus ip) { + + int backKey = 0; + AAPC_Var.setBackKey(backKey); + + FinalizePC fpc = new FinalizePC(); + AAPC_Var.putFinalizePC(fpc); + + AAPC_Var.hideChooseCard(); + + AAPC_Var.showFinalize(); + + + } + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(ChooseCardTemplate.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(ChooseCardTemplate.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(ChooseCardTemplate.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(ChooseCardTemplate.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(new Runnable() { + + public void run() { + new ChooseCardTemplate().setVisible(true); + } + }); + } + // Global variables + int CardType; + // Variables declaration - do not modify + private javax.swing.JLabel ChoiceLabel; + private javax.swing.JLabel FourPhotoLabel; + private javax.swing.JLabel HomeLabel; + private javax.swing.JPanel HomePanel; + private javax.swing.JLabel OnePhotoLabel; + private javax.swing.JPanel OnePhotoPanel; + private javax.swing.JLabel ThreePhotoLabel; + private javax.swing.JLabel TwoPhotoLabel; + private javax.swing.JLabel dataDeviceLabel; + private javax.swing.JLabel egLabel; + private javax.swing.JPanel fourPhotoPanel; + private javax.swing.JLabel horizontal1Label; + private javax.swing.JLabel horizontal2Label; + private javax.swing.JLabel horizontal4Label; + private javax.swing.JPanel threePhotoPanel; + private javax.swing.JPanel twoPhotoPanel; + private javax.swing.JLabel vertical1Label; + private javax.swing.JLabel vertical1horizontal2Label; + private javax.swing.JLabel vertical2Label; + private javax.swing.JLabel vertical2horizontal1Label; + private javax.swing.JLabel vertical4Label; + // End of variables declaration + + //global variables + PostCard postc; + ChooseCardTemplate cct; + String resultsPath; + Boolean horizontal; + int horizonWidth = 1750, horizonHeight = 1150, + verticalWidth = 1150, verticalHeight = 1750, + halfHwidth = 865, halfHheight = 565, + halfVwidth = 565, halfVheight = 865, + pcHW = 1800, pcHH = 1200, + pcVW = 1200, pcVH = 1800, + fullHratio = 1750 / 1150, fullVratio = 1150 / 1750, + halfHratio = 865 / 1150, halfVratio = 1150 / 865, + quarterH = 865 / 565, quarterV = 565 / 865; + int counter = 0; + + void changeText(int language) { + + String s0 = null, s1 = null, s2 = null, s3 = null, + s4 = null, s5 = null, s6 = null, s7 = null; + + switch (language) { + + case 0: + + s0 = "Choose a template:"; + + s1 = "Please connect your data device"; + + s2 = "(e.g., USB-stick, SB card, etc.)"; + + s3 = "One photo"; + + s4 = "Two photos"; + + s5 = "Three photos"; + + s6 = "Four photos"; + + s7 = "Home"; + + break; + + case 1: + + s0 = "noch nicht"; + + s1 = "noch nicht"; + + s2 = "noch nicht"; + + s3 = "noch nicht"; + + s4 = "noch nicht"; + + s5 = "noch nicht"; + + s6 = "noch nicht"; + + s7 = "noch nicht"; + + break; + + case 2: + + s0 = "Spanish"; + + s1 = "Spanish"; + + s2 = "Spanish"; + + s3 = "Spanish"; + + s4 = "Spanish"; + + s5 = "Spanish"; + + s6 = "Spanish"; + + s7 = "Spanish"; + + break; + + case 3: + + s0 = "Italian"; + + s1 = "Italian"; + + s2 = "Italian"; + + s3 = "Italian"; + + s4 = "Italian"; + + s5 = "Italian"; + + s6 = "Italian"; + + s7 = "Italian"; + + break; + + } + + setTextLines(s0, s1, s2, s3, s4, s5, s6, s7); + + } + + private void setTextLines(String s0, String s1, String s2, String s3, String s4, String s5, String s6, String s7) { + + ChoiceLabel.setText(s0); + + dataDeviceLabel.setText(s1); + + egLabel.setText(s2); + + OnePhotoLabel.setText(s3); + + TwoPhotoLabel.setText(s4); + + ThreePhotoLabel.setText(s5); + + FourPhotoLabel.setText(s6); + + HomeLabel.setText(s7); + + } + + void postcardTransfer(PostCard pc, ChooseCardTemplate ct) { + + postc = pc; + + cct = ct; + + } +} \ No newline at end of file diff --git a/src/main/java/Cut_Paste.java b/src/main/java/Cut_Paste.java new file mode 100644 index 0000000..0864aad --- /dev/null +++ b/src/main/java/Cut_Paste.java @@ -0,0 +1,902 @@ +import ij.IJ; +import ij.ImagePlus; +import ij.WindowManager; +import ij.gui.ImageCanvas; +import ij.gui.ImageRoi; +import ij.gui.ImageWindow; +import ij.gui.Overlay; +import ij.gui.Roi; +import ij.plugin.Duplicator; +import ij.plugin.frame.RoiManager; +import ij.process.ImageProcessor; +import java.awt.Dimension; +import java.awt.Rectangle; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import javax.swing.JToggleButton; +import javax.swing.Timer; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/* + * Cut_Paste.java + * + * Created on Oct 16, 2012, 1:14:44 PM + */ +/** + * + * @author chris + */ + +public class Cut_Paste extends javax.swing.JFrame + implements MouseListener, MouseMotionListener { + + /** + * Creates new form Cut_Paste + */ + public Cut_Paste() { + initComponents(); + + Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); + screenHeight = screen.height; + screenWidth = screen.width; + + setUp(); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // + private void initComponents() { + + cutPastePanel = new javax.swing.JPanel(); + InfoScrollPane = new javax.swing.JScrollPane(); + InfoTextArea = new javax.swing.JTextArea(); + ScalePanel = new javax.swing.JPanel(); + LargerButton = new javax.swing.JButton(); + SmallerButton = new javax.swing.JButton(); + RotatePanel = new javax.swing.JPanel(); + ClockwiseButton = new javax.swing.JButton(); + CounterclockwiseButton = new javax.swing.JButton(); + jPanel1 = new javax.swing.JPanel(); + imaToggleButton = new javax.swing.JToggleButton(); + floatButton = new javax.swing.JButton(); + finalizeButton = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); + setTitle("Set Subject"); + setBackground(new java.awt.Color(51, 51, 255)); + + cutPastePanel.setBackground(new java.awt.Color(51, 51, 255)); + + InfoScrollPane.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Image Information", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Comic Sans MS", 0, 13))); // NOI18N + + InfoTextArea.setBackground(new java.awt.Color(50, 150, 255)); + InfoTextArea.setColumns(20); + InfoTextArea.setEditable(false); + InfoTextArea.setFont(new java.awt.Font("Comic Sans MS", 0, 13)); // NOI18N + InfoTextArea.setRows(5); + InfoScrollPane.setViewportView(InfoTextArea); + + ScalePanel.setBackground(new java.awt.Color(50, 150, 255)); + ScalePanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Scale", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Comic Sans MS", 0, 13))); // NOI18N + + LargerButton.setFont(new java.awt.Font("Comic Sans MS", 0, 13)); // NOI18N + LargerButton.setText("Larger"); + LargerButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + largerMousePressed(evt); + } + public void mouseReleased(java.awt.event.MouseEvent evt) { + largerMouseReleased(evt); + } + }); + LargerButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + LargerButtonActionPerformed(evt); + } + }); + + SmallerButton.setFont(new java.awt.Font("Comic Sans MS", 0, 13)); // NOI18N + SmallerButton.setText("Smaller"); + SmallerButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + smallerMousePressed(evt); + } + public void mouseReleased(java.awt.event.MouseEvent evt) { + smallerMouseReleased(evt); + } + }); + SmallerButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + SmallerButtonActionPerformed(evt); + } + }); + + org.jdesktop.layout.GroupLayout ScalePanelLayout = new org.jdesktop.layout.GroupLayout(ScalePanel); + ScalePanel.setLayout(ScalePanelLayout); + ScalePanelLayout.setHorizontalGroup( + ScalePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, ScalePanelLayout.createSequentialGroup() + .add(LargerButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 153, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 10, Short.MAX_VALUE) + .add(SmallerButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 160, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) + ); + + ScalePanelLayout.linkSize(new java.awt.Component[] {LargerButton, SmallerButton}, org.jdesktop.layout.GroupLayout.HORIZONTAL); + + ScalePanelLayout.setVerticalGroup( + ScalePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(ScalePanelLayout.createSequentialGroup() + .add(ScalePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(LargerButton) + .add(SmallerButton)) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + RotatePanel.setBackground(new java.awt.Color(50, 150, 255)); + RotatePanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Rotate", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Comic Sans MS", 0, 13))); // NOI18N + + ClockwiseButton.setFont(new java.awt.Font("Comic Sans MS", 0, 13)); // NOI18N + ClockwiseButton.setText("Clockwise"); + ClockwiseButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + clockwiseMousePressed(evt); + } + public void mouseReleased(java.awt.event.MouseEvent evt) { + clockwiseMouseReleased(evt); + } + }); + ClockwiseButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + ClockwiseButtonActionPerformed(evt); + } + }); + + CounterclockwiseButton.setFont(new java.awt.Font("Comic Sans MS", 0, 13)); // NOI18N + CounterclockwiseButton.setText("Counterclockwise"); + CounterclockwiseButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + counterclockwiseMousePressed(evt); + } + public void mouseReleased(java.awt.event.MouseEvent evt) { + counterclockiwseMouseReleased(evt); + } + }); + CounterclockwiseButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + CounterclockwiseButtonActionPerformed(evt); + } + }); + + org.jdesktop.layout.GroupLayout RotatePanelLayout = new org.jdesktop.layout.GroupLayout(RotatePanel); + RotatePanel.setLayout(RotatePanelLayout); + RotatePanelLayout.setHorizontalGroup( + RotatePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, RotatePanelLayout.createSequentialGroup() + .add(ClockwiseButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 147, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(CounterclockwiseButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 162, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) + ); + + RotatePanelLayout.linkSize(new java.awt.Component[] {ClockwiseButton, CounterclockwiseButton}, org.jdesktop.layout.GroupLayout.HORIZONTAL); + + RotatePanelLayout.setVerticalGroup( + RotatePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(RotatePanelLayout.createSequentialGroup() + .add(RotatePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(ClockwiseButton) + .add(CounterclockwiseButton)) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + jPanel1.setBackground(new java.awt.Color(50, 150, 255)); + jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Developer Area")); + + imaToggleButton.setText("Toggle ima"); + imaToggleButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + imaToggleButtonActionPerformed(evt); + } + }); + + floatButton.setText("float"); + floatButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + floatButtonActionPerformed(evt); + } + }); + + org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1); + jPanel1.setLayout(jPanel1Layout); + jPanel1Layout.setHorizontalGroup( + jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jPanel1Layout.createSequentialGroup() + .add(imaToggleButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 158, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(18, 18, 18) + .add(floatButton) + .add(0, 85, Short.MAX_VALUE)) + ); + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jPanel1Layout.createSequentialGroup() + .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(imaToggleButton) + .add(floatButton)) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + finalizeButton.setText("Finalize"); + finalizeButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + finalizeButtonActionPerformed(evt); + } + }); + + org.jdesktop.layout.GroupLayout cutPastePanelLayout = new org.jdesktop.layout.GroupLayout(cutPastePanel); + cutPastePanel.setLayout(cutPastePanelLayout); + cutPastePanelLayout.setHorizontalGroup( + cutPastePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(0, 360, Short.MAX_VALUE) + .add(cutPastePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(cutPastePanelLayout.createSequentialGroup() + .addContainerGap() + .add(cutPastePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) + .add(InfoScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 348, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(cutPastePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(RotatePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(ScalePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(cutPastePanelLayout.createSequentialGroup() + .add(6, 6, 6) + .add(finalizeButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 159, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) + ); + cutPastePanelLayout.setVerticalGroup( + cutPastePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(0, 398, Short.MAX_VALUE) + .add(cutPastePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(cutPastePanelLayout.createSequentialGroup() + .addContainerGap() + .add(InfoScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 144, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(RotatePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(6, 6, 6) + .add(ScalePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(12, 12, 12) + .add(finalizeButton) + .add(6, 6, 6) + .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) + ); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(cutPastePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(cutPastePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + ); + + pack(); + }// + + private void LargerButtonActionPerformed(java.awt.event.ActionEvent evt) { + + } + + private void SmallerButtonActionPerformed(java.awt.event.ActionEvent evt) { + + } + + private void ClockwiseButtonActionPerformed(java.awt.event.ActionEvent evt) { + + } + + private void CounterclockwiseButtonActionPerformed(java.awt.event.ActionEvent evt) { + + } + + private void imaToggleButtonActionPerformed(java.awt.event.ActionEvent evt) { + + JToggleButton btn = (JToggleButton) evt.getSource(); + if (btn.isSelected()) { + + ips.show(); + + moveWindow(ips, 400, 60); + + ImageWindow iw = new ImageWindow(ips); + + iw.maximize(); + + } else { + + ips.hide(); + + } + + } + + private void clockwiseMousePressed(java.awt.event.MouseEvent evt) { + + angle++; + changeSubject(); //rotateSubject(); + + repeatTimer = new Timer(100, new ActionListener() { + + public void actionPerformed(ActionEvent e) { + angle++; + changeSubject(); //rotateSubject(); + } + }); + repeatTimer.setInitialDelay(100); // start repeating only after 1 second + repeatTimer.start(); + + } + + private void clockwiseMouseReleased(java.awt.event.MouseEvent evt) { + + repeatTimer.stop(); + + } + + private void counterclockwiseMousePressed(java.awt.event.MouseEvent evt) { + + angle--; + changeSubject(); //rotateSubject(); + + repeatTimer = new Timer(100, new ActionListener() { + + public void actionPerformed(ActionEvent e) { + angle--; + changeSubject(); //rotateSubject(); + } + }); + repeatTimer.setInitialDelay(10); // start repeating only after 1 second + repeatTimer.start(); + + } + + private void counterclockiwseMouseReleased(java.awt.event.MouseEvent evt) { + + repeatTimer.stop(); + + } + + private void largerMousePressed(java.awt.event.MouseEvent evt) { + + size+=10; + changeSubject(); //changeSize(); + + repeatTimer = new Timer(100, new ActionListener() { + + public void actionPerformed(ActionEvent e) { + size+=10; + changeSubject(); //changeSize(); + } + }); + repeatTimer.setInitialDelay(10); // start repeating only after 1 second + repeatTimer.start(); + + } + + private void largerMouseReleased(java.awt.event.MouseEvent evt) { + + repeatTimer.stop(); + + } + + private void smallerMousePressed(java.awt.event.MouseEvent evt) { + + size-=10; + changeSubject(); //changeSize(); + + repeatTimer = new Timer(100, new ActionListener() { + + public void actionPerformed(ActionEvent e) { + size-=10; + changeSubject(); //changeSize(); + } + }); + repeatTimer.setInitialDelay(10); // start repeating only after 1 second + repeatTimer.start(); + + } + + private void smallerMouseReleased(java.awt.event.MouseEvent evt) { + + repeatTimer.stop(); + + } + + private void finalizeButtonActionPerformed(java.awt.event.ActionEvent evt) { + + ipp.hide(); + + FinalizePC fpc = new FinalizePC(); + AAPC_Var.putFinalizePC(fpc); + + AAPC_Var.hideCutPaste(); + + AAPC_Var.showFinalize(); + + } + + private void floatButtonActionPerformed(java.awt.event.ActionEvent evt) { + cutPaste(); + } + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(Cut_Paste.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(Cut_Paste.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(Cut_Paste.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(Cut_Paste.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(new Runnable() { + @Override + public void run() { +// new Cut_Paste().setVisible(true); + } + }); + } + // Variables declaration - do not modify + private javax.swing.JButton ClockwiseButton; + private javax.swing.JButton CounterclockwiseButton; + private javax.swing.JScrollPane InfoScrollPane; + private javax.swing.JTextArea InfoTextArea; + private javax.swing.JButton LargerButton; + private javax.swing.JPanel RotatePanel; + private javax.swing.JPanel ScalePanel; + private javax.swing.JButton SmallerButton; + private javax.swing.JPanel cutPastePanel; + private javax.swing.JButton finalizeButton; + private javax.swing.JButton floatButton; + private javax.swing.JToggleButton imaToggleButton; + private javax.swing.JPanel jPanel1; + // End of variables declaration + + // Global variables + + Timer repeatTimer; + + ImageCanvas canvas; + Boolean firstrun = true, + stack = false, + tocard = false, + toPc = false, + setup = false; + + Boolean logWin = false; + ImagePlus ipp, ipt, ips; + ImagePlus pcTemplate, pclayer; + ImageProcessor ipsub; + ImageRoi imageRoi; + RoiManager roiman; + Overlay overlay; + + int pcX, pcY, angle = 0; + int sublen, subject; + int step = 10, + xcen, ycen, angleIndex; + int postcard, screenHeight, screenWidth; + int progressCount = 0; + + double size = 0; + + private void setUp() { + + ipp = AAPC_Var.getImage(); + postcard = ipp.getID(); + + ipt = AAPC_Var.getSubject(); + + ImagePlus temp = WindowManager.getCurrentImage(); + if (WindowManager.getImageCount() > 1 && temp.getStackSize() > 1) { + WindowManager.putBehind(); + } + + ipt = IJ.getImage(); + ipt.hide(); + + int slices = ipp.getNSlices(); + + if (slices > 1) { + stack = true; + ipp.setSlice(2); + + IJ.setTool("rectangle"); + } +// put all relevant under if slices + setup = true; + + resizeSubject(); + + changeSubject(); + + smallStack(); + + IJ.run(ipp, "Layers ", ""); + + pclayer = IJ.getImage(); + + moveWindow(pclayer, 400, 0); + + ipp.setSlice(2); + + setupListener(); + + IJ.selectWindow(postcard); + cutPaste(); + + } + + private void cutPaste() { + + ImagePlus temp = WindowManager.getCurrentImage(); + temp.setSlice(2); + + temp.copy(true); + temp.paste(); + + } + + private void clearPC() { + + IJ.selectWindow(postcard); + IJ.run(ipp, "Select All", ""); + IJ.run(ipp, "Clear", "slice"); + IJ.run(ipp, "Select None", ""); + + } + + private void resizeSubject() { + + int pch = ipp.getHeight(); + + double w = ipt.getWidth(); + double h = ipt.getHeight(); + + double maxD; + + if (w >= h) { + maxD = w; + } else { + maxD = h; + } + + IJ.run(ipt, "Enlarge...", "enlarge=-1"); + + IJ.run(ipt, "Clear Outside", ""); + + ips = IJ.createImage("Subject", "RGB Black", (int) maxD, (int) maxD, 1); + + ipt.copy(false); + ips.paste(); + IJ.run(ips, "Select None", ""); + + IJ.run(ipt, "Canvas Size...", "width=" + maxD + " height=" + maxD + " position=Center zero"); + + } + + private void changeSubject() { + + ImageProcessor ip = ipt.getProcessor(); + ip = ip.duplicate(); + ip = ip.crop(); + + double width = ip.getWidth(); + double height = ip.getHeight(); + + int new_width = (int) (width + size); + int new_height = (int) (height + size); + + if (new_width != 0 || new_height != 0) { + ip.setInterpolate(true); + ip = ip.resize(new_width, new_height); + } + + ip.setBackgroundValue(0.0); + ip.rotate(angle); + + ips.setProcessor("Subject", ip); + ips.updateAndDraw(); + + resetCard(); + + updatePostcard(); + + String s0 = "changeSubject: pcX = " + pcX + " pcY = " + pcY + + "\nsize = " + size + "\nangle = " + angle; + +// toInstructionWidow(s0, true); + + } + + private void smallStack() { + + int w1 = ipp.getWidth(); + int h1 = ipp.getHeight(); + int w2 = (int) ((int) screenWidth - ((int) w1 * .25)); + + ipp.show(); + IJ.selectWindow(postcard); + IJ.run("Set... ", "zoom=25 x=" + (w1 / 2) + " y=" + (h1 / 2)); + + moveWindow(ipp, w2 - 20, 0); + + } + + private void resetCard() { + + ipp.setSlice(2); + IJ.run(ipp, "Select All", ""); + IJ.run(ipp, "Clear", "slice"); + IJ.run(ipp, "Select None", ""); + + } + + private void updatePostcard() { + + ips.copy(false); + + ipp.setSlice(2); + + ipp.paste(); + + ips.hide(); + + Roi roi = ipp.getRoi(); + + Rectangle rec = roi.getBounds(); + + int w0 = rec.width; + int h0 = rec.height; + + if (setup) { + pcX = 0; + pcY = 0; + xcen = (int) pcX + w0 / 2; + ycen = (int) pcY + h0 / 2; + + } else { + pcX = (int) xcen - w0 / 2; + pcY = (int) ycen - h0 / 2; + } + + setup = false; + + ipp.setRoi(pcX, pcY, w0, h0); + ipp.setSlice(2); + + ipp.paste(); +// ipp.updateAndDraw(); + + IJ.selectWindow(postcard); + + String s = "updatePostcard:\npcX = " + pcX + " pcY = " + pcY + + "\nsize = " + size + "\nangle = " + angle + + "\nxcen = " + xcen + "\nycen = " + ycen; + +// toInstructionWidow(s, true); + + } + + public void rotateSubject() { + +// IJ.run("Rotate...", "angle=" + a); + IJ.run(ipp, "Rotate... ", "angle=" + angle + + " grid=1 interpolation=Bilinear"); + + } + + public void changeSize() { + + ImageProcessor ip = ipt.getProcessor(); + ip = ip.duplicate(); + ip = ip.crop(); + + double width = ip.getWidth(); + double height = ip.getHeight(); + + int new_width = 0; + int new_height = 0; + + new_width = (int) (width + size); + new_height = (int) (height + size); + + if (new_width != 0 || new_height != 0) { + ip.setInterpolate(true); + ip = ip.resize(new_width, new_height); + } + + ips.setProcessor("Subject", ip); + ips.updateAndDraw(); + + resetCard(); + + updatePostcard(); + + } + + private void setupListener() { + + ImageWindow win = ipp.getWindow(); + canvas = win.getCanvas(); + canvas.addMouseListener(this); + canvas.addMouseMotionListener(this); + } + + /** + * + * @param me + */ + @Override + public void mouseClicked(MouseEvent me) { +// IJ.log("mouse clicked"); + } + + /** + * + * @param me + */ + @Override + public void mousePressed(MouseEvent me) { +// sublen += 10; +// +// IJ.log("mouse pressed: sublen = " + sublen); + } + + /** + * + * @param me + */ + @Override + public void mouseReleased(MouseEvent me) { +// IJ.log("mouse released"); + +// Rectangle rec = imageRoi.getBounds(); +// int rw = rec.width; +// int rh = rec.height; +// int rx = rec.x + rw / 2; +// int ry = rec.y + rh / 2; +// +// if (logWin) { +// progressCount++; +// IJ.log(progressCount + ": mouseReleased\nrec.width = " +// + rec.width +// + "\nrec.height = " + rec.height +// + "\nrec.x = " + rec.x +// + "\nrec.y = " + rec.y +// + "\nrec.x + rw / 2 = " + rx +// + "\nrec.y + rh / 2 = " + ry); +// } +// pcX = rx; +// pcY = ry; +// +// if (logWin) { +// progressCount++; +// IJ.log(progressCount + ": mouseReleased\nsublen = " + sublen +// + "\nstep = " + step +// + "\npcX = " + pcX +// + "\npcY = " + pcY +// + "\nangle = " + angle); +// } +// +// String s = "mouseReleased: " + "\nimageRoi width = " + rw + ", imageRoi height = " + rh +// + "\nrec.x = " + rec.x + ", rec.y = " + rec.y +// + "\nrec.width = " + rec.width +// + "\ncenter x = " + pcX +// + "\ncenter y = " + pcY; +// +// toInstructionWidow(s, true); + + } + + /** + * + * @param me + */ + @Override + public void mouseEntered(MouseEvent me) { +// IJ.log("mouse entered"); + } + + /** + * + * @param me + */ + @Override + public void mouseExited(MouseEvent me) { + + Roi roi = ipp.getRoi(); + Rectangle rec = roi.getBounds(); + pcX = rec.x; + pcY = rec.y; + int wid = rec.width; + int hit = rec.height; + + xcen = (int) pcX + wid / 2; + ycen = (int) pcY + hit / 2; + + String s = "mouseExited:\npcX = " + pcX + + "\npcY = " + pcY + + "\nxcen = " + xcen + "\nycen = " + ycen + + "\nROI width = " + wid; + + toInstructionWidow(s, true); + + } + + /** + * + * @param me + */ + @Override + public void mouseDragged(MouseEvent me) { +// IJ.log("mouse dragged"); + } + + /** + * + * @param me + */ + @Override + public void mouseMoved(MouseEvent me) { +// IJ.log("mouse moved"); + } + + private void toInstructionWidow(String s, Boolean go) { + if (go) { + String s1 = InfoTextArea.getText(); + String s2 = "\n*******************\n"; + InfoTextArea.setText(s1 + s2 + s); + } else { + InfoTextArea.setText(s); + } + } + + private void moveWindow(ImagePlus impl, int x, int y) { + + impl.getWindow().setLocation(x, y); + + } +} \ No newline at end of file diff --git a/src/main/java/FinalizePC.java b/src/main/java/FinalizePC.java new file mode 100644 index 0000000..f76a1e7 --- /dev/null +++ b/src/main/java/FinalizePC.java @@ -0,0 +1,829 @@ +import ij.IJ; +import ij.ImagePlus; +import ij.gui.TextRoi; +import java.awt.Color; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.Timer; + +/* + * FinalizePC.java + * + * Created on Jul 2, 2012, 4:21:57 PM + */ +/** + * Copyright Jun 7, 2012 The GAIA Group http://gaiag.net + * + * @author chris + */ +public class FinalizePC extends javax.swing.JFrame { + + /** + * Creates new form FinalizePC + */ + public FinalizePC() { + initComponents(); + + smallerFontButton.setOpaque(true); + smallerFontButton.setBackground(Color.CYAN); + + largerFontButton.setOpaque(true); + largerFontButton.setBackground(Color.CYAN); + + TextRoi.setFont(fonttype, fontsize, Font.PLAIN); + + String s1 = "To write something on the front of the postcard," + + "\nclick on the image and start typing. Use the" + + "\nbuttons to change the font style, size and color." + + "\nClick and drag to where you want the message." + + "\nClick the Finish button to complete your card."; + toTextWindow(s1, false); + + imp = IJ.getImage(); // AAPC_Var.getImage(); + +// imp = IJ.openImage("/Users/chris/Documents/GAIA_Projects/*Daniel Weth /testImages/Argonauti.tif"); + imp.show(); + + moveWindow(imp, 400, 0); + + IJ.setTool("text"); + + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // + private void initComponents() { + + finalizePanel = new javax.swing.JPanel(); + smallerFontButton = new javax.swing.JButton(); + largerFontButton = new javax.swing.JButton(); + fontColorLabel = new javax.swing.JLabel(); + fontBlackLabel = new javax.swing.JLabel(); + fontRedLabel = new javax.swing.JLabel(); + fontGreenLabel = new javax.swing.JLabel(); + fontPurpleLabel = new javax.swing.JLabel(); + fontTypeLabel = new javax.swing.JLabel(); + font1Label = new javax.swing.JLabel(); + font3Label = new javax.swing.JLabel(); + font4Label = new javax.swing.JLabel(); + font5Label = new javax.swing.JLabel(); + finalizeButton = new javax.swing.JButton(); + finishButton = new javax.swing.JButton(); + instructionScrollPane = new javax.swing.JScrollPane(); + instructionTextArea = new javax.swing.JTextArea(); + colorBlackLabel = new javax.swing.JLabel(); + colorWhiteLabel = new javax.swing.JLabel(); + color3Label = new javax.swing.JLabel(); + color4Label = new javax.swing.JLabel(); + color5Label = new javax.swing.JLabel(); + color6Label = new javax.swing.JLabel(); + color7Label = new javax.swing.JLabel(); + color8Label = new javax.swing.JLabel(); + color9Label = new javax.swing.JLabel(); + color10Label = new javax.swing.JLabel(); + color11Label = new javax.swing.JLabel(); + color12Label = new javax.swing.JLabel(); + color13Label = new javax.swing.JLabel(); + color14Label = new javax.swing.JLabel(); + color15Label = new javax.swing.JLabel(); + font6Label = new javax.swing.JLabel(); + font2Label = new javax.swing.JLabel(); + + setBackground(new java.awt.Color(31, 73, 125)); + + finalizePanel.setBackground(new java.awt.Color(31, 73, 125)); + + smallerFontButton.setBackground(new java.awt.Color(50, 255, 255)); + smallerFontButton.setFont(new java.awt.Font("Comic Sans MS", 0, 18)); // NOI18N + smallerFontButton.setText("Smaller Font"); + smallerFontButton.setMargin(new java.awt.Insets(0, 5, 0, 5)); + smallerFontButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + smallerFontMousePressed(evt); + } + public void mouseReleased(java.awt.event.MouseEvent evt) { + smallFontMouseReleased(evt); + } + }); + smallerFontButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + smallerFontButtonActionPerformed(evt); + } + }); + + largerFontButton.setBackground(new java.awt.Color(102, 204, 255)); + largerFontButton.setFont(new java.awt.Font("Comic Sans MS", 0, 18)); // NOI18N + largerFontButton.setText("Larger Font"); + largerFontButton.setMargin(new java.awt.Insets(0, 5, 0, 5)); + largerFontButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + largerFontMousePressed(evt); + } + public void mouseReleased(java.awt.event.MouseEvent evt) { + largeFontMouseReleased(evt); + } + }); + largerFontButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + largerFontButtonActionPerformed(evt); + } + }); + + fontColorLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 24)); // NOI18N + fontColorLabel.setForeground(new java.awt.Color(230, 224, 236)); + fontColorLabel.setText("Please choose the font color"); + + fontBlackLabel.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + blackClicked(evt); + } + }); + + fontRedLabel.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + redClicked(evt); + } + }); + + fontGreenLabel.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + greenClicked(evt); + } + }); + + fontPurpleLabel.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + purpleClicked(evt); + } + }); + + fontTypeLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 24)); // NOI18N + fontTypeLabel.setForeground(new java.awt.Color(230, 224, 236)); + fontTypeLabel.setText("Please choose the font type"); + + font1Label.setBackground(new java.awt.Color(51, 153, 255)); + font1Label.setFont(new java.awt.Font("Arial", 0, 24)); // NOI18N + font1Label.setForeground(new java.awt.Color(230, 224, 236)); + font1Label.setText("Greetings"); + font1Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + font1Clicked(evt); + } + }); + + font3Label.setBackground(new java.awt.Color(51, 153, 255)); + font3Label.setFont(new java.awt.Font("Edwardian Script ITC", 0, 36)); // NOI18N + font3Label.setForeground(new java.awt.Color(230, 224, 236)); + font3Label.setText("Greetings"); + font3Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + font3Clicked(evt); + } + }); + + font4Label.setBackground(new java.awt.Color(51, 153, 255)); + font4Label.setFont(new java.awt.Font("Lucida Handwriting", 0, 24)); // NOI18N + font4Label.setForeground(new java.awt.Color(230, 224, 236)); + font4Label.setText("Greetings"); + font4Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + font4Clicked(evt); + } + }); + + font5Label.setBackground(new java.awt.Color(51, 153, 255)); + font5Label.setFont(new java.awt.Font("Mistral", 0, 36)); // NOI18N + font5Label.setForeground(new java.awt.Color(230, 224, 236)); + font5Label.setText("Greetings"); + font5Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + font5Clicked(evt); + } + }); + + finalizeButton.setBackground(new java.awt.Color(50, 255, 255)); + finalizeButton.setFont(new java.awt.Font("Comic Sans MS", 0, 18)); // NOI18N + finalizeButton.setText("Set"); + finalizeButton.setMargin(new java.awt.Insets(0, 5, 0, 5)); + finalizeButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + finalizeButtonActionPerformed(evt); + } + }); + + finishButton.setBackground(new java.awt.Color(50, 255, 255)); + finishButton.setFont(new java.awt.Font("Comic Sans MS", 0, 18)); // NOI18N + finishButton.setText("Finish"); + finishButton.setMargin(new java.awt.Insets(0, 5, 0, 5)); + finishButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + finishButtonActionPerformed(evt); + } + }); + + instructionTextArea.setEditable(false); + instructionTextArea.setBackground(new java.awt.Color(50, 150, 255)); + instructionTextArea.setColumns(20); + instructionTextArea.setFont(new java.awt.Font("Comic Sans MS", 0, 18)); // NOI18N + instructionTextArea.setRows(5); + instructionTextArea.setBorder(null); + instructionScrollPane.setViewportView(instructionTextArea); + + colorBlackLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/FontColorBlack.jpg"))); // NOI18N + colorBlackLabel.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + blackClicked(evt); + } + }); + + colorWhiteLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/FontColorWhite.jpg"))); // NOI18N + colorWhiteLabel.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + whiteClicked(evt); + } + }); + + color3Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fontcolor3.jpg"))); // NOI18N + color3Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + color3Clicked(evt); + } + }); + + color4Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fontcolor4.jpg"))); // NOI18N + color4Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + color4Clicked(evt); + } + }); + + color5Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fontcolor5.jpg"))); // NOI18N + color5Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + color5Clicked(evt); + } + }); + + color6Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fontcolor6.jpg"))); // NOI18N + color6Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + color6Clicked(evt); + } + }); + + color7Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fontcolor7.jpg"))); // NOI18N + color7Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + color7Clicked(evt); + } + }); + + color8Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fontcolor8.jpg"))); // NOI18N + color8Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + color8Clicked(evt); + } + }); + + color9Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fontcolor9.jpg"))); // NOI18N + color9Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + color9Clicked(evt); + } + }); + + color10Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fontcolor10.jpg"))); // NOI18N + color10Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + color10Clicked(evt); + } + }); + + color11Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fontcolor11.jpg"))); // NOI18N + color11Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + color11Clicked(evt); + } + }); + + color12Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fontcolor12.jpg"))); // NOI18N + color12Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + color12Clicked(evt); + } + }); + + color13Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fontcolor13.jpg"))); // NOI18N + color13Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + color13Clicked(evt); + } + }); + + color14Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fontcolor14.jpg"))); // NOI18N + color14Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + color14Clicked(evt); + } + }); + + color15Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fontcolor15.jpg"))); // NOI18N + color15Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + color15Clicked(evt); + } + }); + + font6Label.setBackground(new java.awt.Color(51, 153, 255)); + font6Label.setFont(new java.awt.Font("Plantagenet Cherokee", 0, 24)); // NOI18N + font6Label.setForeground(new java.awt.Color(230, 224, 236)); + font6Label.setText("Greetings"); + font6Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + font6Clicked(evt); + } + }); + + font2Label.setBackground(new java.awt.Color(51, 153, 255)); + font2Label.setFont(new java.awt.Font("Curlz MT", 0, 24)); // NOI18N + font2Label.setForeground(new java.awt.Color(230, 224, 236)); + font2Label.setText("Greetings"); + font2Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + font2Clicked(evt); + } + }); + + org.jdesktop.layout.GroupLayout finalizePanelLayout = new org.jdesktop.layout.GroupLayout(finalizePanel); + finalizePanel.setLayout(finalizePanelLayout); + finalizePanelLayout.setHorizontalGroup( + finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(finalizePanelLayout.createSequentialGroup() + .addContainerGap() + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(finalizePanelLayout.createSequentialGroup() + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) + .add(org.jdesktop.layout.GroupLayout.LEADING, finalizePanelLayout.createSequentialGroup() + .add(6, 6, 6) + .add(smallerFontButton) + .add(103, 103, 103) + .add(largerFontButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 156, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(org.jdesktop.layout.GroupLayout.LEADING, finalizePanelLayout.createSequentialGroup() + .add(colorBlackLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(18, 18, 18) + .add(colorWhiteLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(18, 18, 18) + .add(color3Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(org.jdesktop.layout.GroupLayout.LEADING, finalizePanelLayout.createSequentialGroup() + .add(color5Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(18, 18, 18) + .add(color4Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(18, 18, 18) + .add(color6Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(org.jdesktop.layout.GroupLayout.LEADING, finalizePanelLayout.createSequentialGroup() + .add(color7Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(18, 18, 18) + .add(color8Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(18, 18, 18) + .add(color9Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(org.jdesktop.layout.GroupLayout.LEADING, finalizePanelLayout.createSequentialGroup() + .add(color10Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(18, 18, 18) + .add(color11Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(18, 18, 18) + .add(color12Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(org.jdesktop.layout.GroupLayout.LEADING, fontColorLabel) + .add(org.jdesktop.layout.GroupLayout.LEADING, fontTypeLabel) + .add(org.jdesktop.layout.GroupLayout.LEADING, instructionScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 431, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(org.jdesktop.layout.GroupLayout.LEADING, finalizePanelLayout.createSequentialGroup() + .add(color13Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(18, 18, 18) + .add(color14Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(18, 18, 18) + .add(color15Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(org.jdesktop.layout.GroupLayout.LEADING, finalizePanelLayout.createSequentialGroup() + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(font3Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 186, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(font5Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 200, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(59, 59, 59) + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(font6Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(font2Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 119, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .add(org.jdesktop.layout.GroupLayout.TRAILING, finalizePanelLayout.createSequentialGroup() + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) + .add(finalizePanelLayout.createSequentialGroup() + .add(finalizeButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 156, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(finishButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 156, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(finalizePanelLayout.createSequentialGroup() + .add(font1Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 195, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(font4Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 155, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) + .add(48, 48, 48)))) + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(finalizePanelLayout.createSequentialGroup() + .add(0, 222, Short.MAX_VALUE) + .add(fontBlackLabel) + .add(0, 221, Short.MAX_VALUE))) + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(finalizePanelLayout.createSequentialGroup() + .add(0, 222, Short.MAX_VALUE) + .add(fontRedLabel) + .add(0, 221, Short.MAX_VALUE))) + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(finalizePanelLayout.createSequentialGroup() + .add(0, 222, Short.MAX_VALUE) + .add(fontGreenLabel) + .add(0, 221, Short.MAX_VALUE))) + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(finalizePanelLayout.createSequentialGroup() + .add(0, 222, Short.MAX_VALUE) + .add(fontPurpleLabel) + .add(0, 221, Short.MAX_VALUE))) + ); + finalizePanelLayout.setVerticalGroup( + finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(finalizePanelLayout.createSequentialGroup() + .addContainerGap() + .add(instructionScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(smallerFontButton) + .add(largerFontButton)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(fontColorLabel) + .add(18, 18, 18) + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, colorBlackLabel) + .add(org.jdesktop.layout.GroupLayout.TRAILING, colorWhiteLabel) + .add(org.jdesktop.layout.GroupLayout.TRAILING, color3Label)) + .add(18, 18, 18) + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(color4Label) + .add(color5Label) + .add(color6Label)) + .add(18, 18, 18) + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(finalizePanelLayout.createSequentialGroup() + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(color8Label) + .add(color7Label)) + .add(18, 18, 18) + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(finalizePanelLayout.createSequentialGroup() + .add(color12Label) + .add(18, 18, 18) + .add(color15Label) + .add(0, 0, Short.MAX_VALUE)) + .add(finalizePanelLayout.createSequentialGroup() + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(color10Label) + .add(color11Label)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(color14Label) + .add(color13Label))))) + .add(color9Label)) + .add(36, 36, 36) + .add(fontTypeLabel) + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(font1Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 48, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(font4Label)) + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(font3Label) + .add(font2Label)) + .add(18, 18, 18) + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(font5Label, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(font6Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(finalizeButton) + .add(finishButton)) + .add(238, 238, 238)) + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(finalizePanelLayout.createSequentialGroup() + .add(0, 519, Short.MAX_VALUE) + .add(fontBlackLabel) + .add(0, 518, Short.MAX_VALUE))) + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(finalizePanelLayout.createSequentialGroup() + .add(0, 519, Short.MAX_VALUE) + .add(fontRedLabel) + .add(0, 518, Short.MAX_VALUE))) + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(finalizePanelLayout.createSequentialGroup() + .add(0, 519, Short.MAX_VALUE) + .add(fontGreenLabel) + .add(0, 518, Short.MAX_VALUE))) + .add(finalizePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(finalizePanelLayout.createSequentialGroup() + .add(0, 519, Short.MAX_VALUE) + .add(fontPurpleLabel) + .add(0, 518, Short.MAX_VALUE))) + ); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(finalizePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(finalizePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 807, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) + ); + + pack(); + }// + + private void smallerFontButtonActionPerformed(java.awt.event.ActionEvent evt) { +// fontsize = 72; +// TextRoi.setFont(fonttype, fontsize, Font.PLAIN); + } + + private void largerFontButtonActionPerformed(java.awt.event.ActionEvent evt) { +// fontsize = 150; +// TextRoi.setFont(fonttype, fontsize, Font.PLAIN); + } + + private void redClicked(java.awt.event.MouseEvent evt) { + IJ.setForegroundColor(255, 0, 0); //red + } + + private void blackClicked(java.awt.event.MouseEvent evt) { + IJ.setForegroundColor(0, 0, 0); //black + } + + private void greenClicked(java.awt.event.MouseEvent evt) { + IJ.setForegroundColor(0, 255, 0); //green + } + + private void purpleClicked(java.awt.event.MouseEvent evt) { + IJ.setForegroundColor(209, 93, 254); //purple + } + + private void font1Clicked(java.awt.event.MouseEvent evt) { + fonttype = "Ariel"; + TextRoi.setFont(fonttype, fontsize, Font.PLAIN); + } + + private void font2Clicked(java.awt.event.MouseEvent evt) { + fonttype = "Curlz MT"; + TextRoi.setFont(fonttype, fontsize, Font.PLAIN); + } + + private void font3Clicked(java.awt.event.MouseEvent evt) { + fonttype = "Edwardian Script ITC"; + TextRoi.setFont(fonttype, fontsize, Font.PLAIN); + } + + private void font4Clicked(java.awt.event.MouseEvent evt) { + fonttype = "Lucida Handwriting"; + TextRoi.setFont(fonttype, fontsize, Font.PLAIN); + } + + private void font5Clicked(java.awt.event.MouseEvent evt) { + fonttype = "Mistral"; + TextRoi.setFont(fonttype, fontsize, Font.PLAIN); + } + + private void font6Clicked(java.awt.event.MouseEvent evt) { + fonttype = "Plantagenet Cherokee"; + TextRoi.setFont(fonttype, fontsize, Font.PLAIN); + } + + private void finishButtonActionPerformed(java.awt.event.ActionEvent evt) { + + ImagePlus imp = IJ.getImage(); + + boolean isRoi = imp.getRoi() != null; + if (isRoi) { + IJ.run(imp, "Draw", ""); + IJ.run(imp, "Select None", ""); + } + + AAPC_Var.hideFinalize(); + + PrintCard pc = new PrintCard(); + pc.setVisible(true); + + } + + private void finalizeButtonActionPerformed(java.awt.event.ActionEvent evt) { + + ImagePlus imp = IJ.getImage(); + + boolean isRoi = imp.getRoi() != null; + if (isRoi) { + IJ.run(imp, "Draw", ""); + IJ.run(imp, "Select None", ""); + } + + } + + private void whiteClicked(java.awt.event.MouseEvent evt) { + IJ.setForegroundColor(255, 255, 255); //white + } + + private void smallerFontMousePressed(java.awt.event.MouseEvent evt) { + + fontsize--; + + repeatTimer = new Timer(100, new ActionListener() { + @Override + public void actionPerformed(ActionEvent ae) { + fontsize--; + TextRoi.setFont(fonttype, fontsize, Font.PLAIN); + } + }); + repeatTimer.setInitialDelay(10); // start repeating only after 1 second + repeatTimer.start(); + + } + + private void largerFontMousePressed(java.awt.event.MouseEvent evt) { + + fontsize++; + + repeatTimer = new Timer(100, new ActionListener() { + @Override + public void actionPerformed(ActionEvent ae) { + fontsize++; + TextRoi.setFont(fonttype, fontsize, Font.PLAIN); + } + }); + repeatTimer.setInitialDelay(10); // start repeating only after 1 second + repeatTimer.start(); + + } + + private void smallFontMouseReleased(java.awt.event.MouseEvent evt) { + + repeatTimer.stop(); + + } + + private void largeFontMouseReleased(java.awt.event.MouseEvent evt) { + + repeatTimer.stop(); + + } + + private void color3Clicked(java.awt.event.MouseEvent evt) { + IJ.setForegroundColor(147, 98, 49); //black + } + + private void color4Clicked(java.awt.event.MouseEvent evt) { + IJ.setForegroundColor(192, 0, 0); //black + } + + private void color5Clicked(java.awt.event.MouseEvent evt) { + IJ.setForegroundColor(255, 0, 0); //black + } + + private void color6Clicked(java.awt.event.MouseEvent evt) { + IJ.setForegroundColor(255, 192, 0); //black + } + + private void color7Clicked(java.awt.event.MouseEvent evt) { + IJ.setForegroundColor(255, 153, 204); //black + } + + private void color8Clicked(java.awt.event.MouseEvent evt) { + IJ.setForegroundColor(255, 255, 0); //black + } + + private void color9Clicked(java.awt.event.MouseEvent evt) { + IJ.setForegroundColor(153, 255, 51); //black + } + + private void color10Clicked(java.awt.event.MouseEvent evt) { + IJ.setForegroundColor(146, 208, 80); //black + } + + private void color11Clicked(java.awt.event.MouseEvent evt) { + IJ.setForegroundColor(0, 176, 80); //black + } + + private void color12Clicked(java.awt.event.MouseEvent evt) { + IJ.setForegroundColor(125, 221, 255); //black + } + + private void color13Clicked(java.awt.event.MouseEvent evt) { + IJ.setForegroundColor(0, 112, 192); //black + } + + private void color14Clicked(java.awt.event.MouseEvent evt) { + IJ.setForegroundColor(0, 32, 96); //black + } + + private void color15Clicked(java.awt.event.MouseEvent evt) { + IJ.setForegroundColor(112, 68, 160); //black + } + + public void toTextWindow(String s, Boolean go) { + if (go) { + String s1 = instructionTextArea.getText(); + String s2 = "\n*******************\n"; + instructionTextArea.setText(s1 + s2 + s); + } else { + instructionTextArea.setText(s); + } + } + + private void moveWindow(ImagePlus impl, int x, int y) { + + impl.getWindow().setLocation(x, y); + + } + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(FinalizePC.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(FinalizePC.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(FinalizePC.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(FinalizePC.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new FinalizePC().setVisible(true); + } + }); + } + // Variables declaration - do not modify + private javax.swing.JLabel color10Label; + private javax.swing.JLabel color11Label; + private javax.swing.JLabel color12Label; + private javax.swing.JLabel color13Label; + private javax.swing.JLabel color14Label; + private javax.swing.JLabel color15Label; + private javax.swing.JLabel color3Label; + private javax.swing.JLabel color4Label; + private javax.swing.JLabel color5Label; + private javax.swing.JLabel color6Label; + private javax.swing.JLabel color7Label; + private javax.swing.JLabel color8Label; + private javax.swing.JLabel color9Label; + private javax.swing.JLabel colorBlackLabel; + private javax.swing.JLabel colorWhiteLabel; + private javax.swing.JButton finalizeButton; + private javax.swing.JPanel finalizePanel; + private javax.swing.JButton finishButton; + private javax.swing.JLabel font1Label; + private javax.swing.JLabel font2Label; + private javax.swing.JLabel font3Label; + private javax.swing.JLabel font4Label; + private javax.swing.JLabel font5Label; + private javax.swing.JLabel font6Label; + private javax.swing.JLabel fontBlackLabel; + private javax.swing.JLabel fontColorLabel; + private javax.swing.JLabel fontGreenLabel; + private javax.swing.JLabel fontPurpleLabel; + private javax.swing.JLabel fontRedLabel; + private javax.swing.JLabel fontTypeLabel; + private javax.swing.JScrollPane instructionScrollPane; + private javax.swing.JTextArea instructionTextArea; + private javax.swing.JButton largerFontButton; + private javax.swing.JButton smallerFontButton; + // End of variables declaration + // global variables + Timer repeatTimer; + ImagePlus imp; + String fonttype = "Comic Sans MS"; + int fontsize = 72; +} diff --git a/src/main/java/FinishingTouches.java b/src/main/java/FinishingTouches.java new file mode 100644 index 0000000..17db6e5 --- /dev/null +++ b/src/main/java/FinishingTouches.java @@ -0,0 +1,1357 @@ +import ij.IJ; +import ij.ImagePlus; +import ij.WindowManager; +import ij.gui.ImageCanvas; +import ij.gui.ImageRoi; +import ij.gui.ImageWindow; +import ij.gui.Overlay; +import ij.gui.Roi; +import ij.measure.ResultsTable; +import ij.plugin.Duplicator; +import ij.plugin.ImageCalculator; +import ij.plugin.filter.Analyzer; +import ij.plugin.frame.RoiManager; +import ij.process.ImageProcessor; +import java.awt.EventQueue; +import java.awt.Frame; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.awt.image.DirectColorModel; +import javax.swing.Timer; +import java.util.TimerTask; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import javax.swing.JToggleButton; +import javax.swing.SwingUtilities; + +/* + * FinishingTouches.java + * + * Created on Jul 7, 2012, 7:16:11 PM + */ +/** + * Copyright Jun 7, 2012 The GAIA Group + * http://gaiag.net + * + * @author chris + */ +public class FinishingTouches extends javax.swing.JFrame + implements MouseListener, MouseMotionListener { + + // Global Variables + ImagePlus imp, img, pcs, + imj, ipl, ipm; + ImageProcessor crop; + int language, angle = 0; + ; + int x0, y0, pcX, pcY, + outX, outY, + iter, rotate, + dimOutline, + outW, outH, + hypotenuse; + int[][] allOutlines, borders; + double[] borderValues; + boolean noOutline, redo = false, + resize = false, refresh = false, + text = false, start = false, + isolate = false, + rotation = true, spin = false, + spinback = false; + ImageCanvas canvas; + Roi outline; + RoiManager roiman; + Overlay overlay; + ImageRoi imageRoi; + Timer repeatTimer; + + /** Creates new form FinishingTouches */ + public FinishingTouches() { + initComponents(); + + startUp(); + + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // + private void initComponents() { + + informationScrollPane = new javax.swing.JScrollPane(); + informationTextArea = new javax.swing.JTextArea(); + jPanel1 = new javax.swing.JPanel(); + counterClockwiseButton = new javax.swing.JButton(); + clockwiseButton = new javax.swing.JButton(); + textButton = new javax.swing.JButton(); + justFinishButton = new javax.swing.JButton(); + jPanel2 = new javax.swing.JPanel(); + subjectToggleButton = new javax.swing.JToggleButton(); + iplToggleButton = new javax.swing.JToggleButton(); + pcsToggleButton = new javax.swing.JToggleButton(); + ipmToggleButton = new javax.swing.JToggleButton(); + imjToggleButton = new javax.swing.JToggleButton(); + overlayToggleButton = new javax.swing.JToggleButton(); + outlineROIToggleButton = new javax.swing.JToggleButton(); + pixelBorderToggleButton = new javax.swing.JToggleButton(); + backButton = new javax.swing.JButton(); + homeButton = new javax.swing.JButton(); + + setBackground(new java.awt.Color(0, 0, 255)); + + informationScrollPane.setBackground(new java.awt.Color(50, 150, 255)); + + informationTextArea.setBackground(new java.awt.Color(50, 150, 255)); + informationTextArea.setColumns(20); + informationTextArea.setEditable(false); + informationTextArea.setFont(new java.awt.Font("Comic Sans MS", 0, 14)); // NOI18N + informationTextArea.setForeground(new java.awt.Color(255, 255, 255)); + informationTextArea.setLineWrap(true); + informationTextArea.setRows(5); + informationTextArea.setText("1. Click and drag on the subject to change the position. \n2. Click and drag the handles (corners) to change the size.\n3. To rotate the subject, when the position and size are correct, click the clockwise or counterclockwise buttons.\n4. When complete, click the \"Add a message...\" or \"Just finish...\" button."); + informationTextArea.setBorder(javax.swing.BorderFactory.createEmptyBorder(4, 4, 4, 4)); + informationScrollPane.setViewportView(informationTextArea); + + jPanel1.setBackground(new java.awt.Color(50, 150, 255)); + jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Change Subject Rotation", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Comic Sans MS", 0, 24), new java.awt.Color(255, 255, 255))); // NOI18N + + counterClockwiseButton.setFont(new java.awt.Font("Comic Sans MS", 0, 14)); // NOI18N + counterClockwiseButton.setText("Counterclockwise"); + counterClockwiseButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + counterClockwiseButtonMousePressed(evt); + } + public void mouseReleased(java.awt.event.MouseEvent evt) { + counterClockwiseButtonMouseReleased(evt); + } + public void mouseClicked(java.awt.event.MouseEvent evt) { + counterClockwiseButtonMouseClicked(evt); + } + }); + counterClockwiseButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + counterClockwiseButtonActionPerformed(evt); + } + }); + + clockwiseButton.setFont(new java.awt.Font("Comic Sans MS", 0, 14)); // NOI18N + clockwiseButton.setText("Clockwise"); + clockwiseButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + clockwiseButtonMousePressed(evt); + } + public void mouseReleased(java.awt.event.MouseEvent evt) { + clockwiseButtonMouseReleased(evt); + } + public void mouseClicked(java.awt.event.MouseEvent evt) { + clockwiseButtonMouseClicked(evt); + } + public void mouseEntered(java.awt.event.MouseEvent evt) { + clockwiseButtonMouseEntered(evt); + } + }); + clockwiseButton.addChangeListener(new javax.swing.event.ChangeListener() { + public void stateChanged(javax.swing.event.ChangeEvent evt) { + clockwiseButtonStateChanged(evt); + } + }); + clockwiseButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + clockwiseButtonActionPerformed(evt); + } + }); + clockwiseButton.addKeyListener(new java.awt.event.KeyAdapter() { + public void keyPressed(java.awt.event.KeyEvent evt) { + clockwiseButtonKeyPressed(evt); + } + public void keyReleased(java.awt.event.KeyEvent evt) { + clockwiseButtonKeyReleased(evt); + } + }); + + org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1); + jPanel1.setLayout(jPanel1Layout); + jPanel1Layout.setHorizontalGroup( + jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jPanel1Layout.createSequentialGroup() + .add(clockwiseButton) + .add(18, 18, 18) + .add(counterClockwiseButton) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + jPanel1Layout.linkSize(new java.awt.Component[] {clockwiseButton, counterClockwiseButton}, org.jdesktop.layout.GroupLayout.HORIZONTAL); + + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(clockwiseButton) + .add(counterClockwiseButton)) + ); + + textButton.setFont(new java.awt.Font("Comic Sans MS", 0, 14)); // NOI18N + textButton.setText("Add a message to the card front"); + textButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + textButtonActionPerformed(evt); + } + }); + + justFinishButton.setFont(new java.awt.Font("Comic Sans MS", 0, 14)); // NOI18N + justFinishButton.setText("Just finish without message"); + justFinishButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + justFinishButtonActionPerformed(evt); + } + }); + + jPanel2.setBackground(new java.awt.Color(50, 150, 255)); + jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Developer Area. Don't mess with it!", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Lucida Grande", 0, 13), new java.awt.Color(255, 255, 255))); // NOI18N + jPanel2.setForeground(new java.awt.Color(255, 255, 255)); + + subjectToggleButton.setText("subject"); + subjectToggleButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + subjectToggleButtonActionPerformed(evt); + } + }); + + iplToggleButton.setText("ipl"); + iplToggleButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + iplToggleButtonActionPerformed(evt); + } + }); + + pcsToggleButton.setText("pcs"); + pcsToggleButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + pcsToggleButtonActionPerformed(evt); + } + }); + + ipmToggleButton.setText("ipm"); + ipmToggleButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + ipmToggleButtonActionPerformed(evt); + } + }); + + imjToggleButton.setText("imj"); + imjToggleButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + imjToggleButtonActionPerformed(evt); + } + }); + + overlayToggleButton.setText("overlay"); + overlayToggleButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + overlayToggleButtonActionPerformed(evt); + } + }); + + outlineROIToggleButton.setText("outlineROI"); + outlineROIToggleButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + outlineROIToggleButtonActionPerformed(evt); + } + }); + + pixelBorderToggleButton.setText("pixelBorder"); + pixelBorderToggleButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + pixelBorderToggleButtonActionPerformed(evt); + } + }); + + org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2); + jPanel2.setLayout(jPanel2Layout); + jPanel2Layout.setHorizontalGroup( + jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jPanel2Layout.createSequentialGroup() + .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jPanel2Layout.createSequentialGroup() + .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(subjectToggleButton) + .add(pcsToggleButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(18, 18, 18) + .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(ipmToggleButton) + .add(iplToggleButton))) + .add(imjToggleButton)) + .add(14, 14, 14) + .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(overlayToggleButton) + .add(outlineROIToggleButton) + .add(pixelBorderToggleButton)) + .addContainerGap(25, Short.MAX_VALUE)) + ); + + jPanel2Layout.linkSize(new java.awt.Component[] {imjToggleButton, pcsToggleButton, subjectToggleButton}, org.jdesktop.layout.GroupLayout.HORIZONTAL); + + jPanel2Layout.linkSize(new java.awt.Component[] {outlineROIToggleButton, overlayToggleButton, pixelBorderToggleButton}, org.jdesktop.layout.GroupLayout.HORIZONTAL); + + jPanel2Layout.setVerticalGroup( + jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jPanel2Layout.createSequentialGroup() + .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(overlayToggleButton) + .add(subjectToggleButton) + .add(iplToggleButton)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(outlineROIToggleButton) + .add(pcsToggleButton) + .add(ipmToggleButton)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(pixelBorderToggleButton) + .add(imjToggleButton))) + ); + + backButton.setFont(new java.awt.Font("Comic Sans MS", 0, 14)); // NOI18N + backButton.setText("Back"); + backButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + backButtonActionPerformed(evt); + } + }); + + homeButton.setFont(new java.awt.Font("Comic Sans MS", 0, 14)); // NOI18N + homeButton.setText("Home"); + homeButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + homeButtonActionPerformed(evt); + } + }); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) + .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 346, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(textButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 341, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false) + .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup() + .add(backButton) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(homeButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 159, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(org.jdesktop.layout.GroupLayout.LEADING, justFinishButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 341, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))) + .add(29, 29, 29)) + .add(layout.createSequentialGroup() + .add(informationScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE) + .addContainerGap()))) + ); + + layout.linkSize(new java.awt.Component[] {backButton, homeButton}, org.jdesktop.layout.GroupLayout.HORIZONTAL); + + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .add(12, 12, 12) + .add(informationScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(18, 18, 18) + .add(textButton) + .add(4, 4, 4) + .add(justFinishButton) + .add(18, 18, 18) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(backButton) + .add(homeButton)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(20, 20, 20)) + ); + + pack(); + }// + + private void textButtonActionPerformed(java.awt.event.ActionEvent evt) { + + IJ.run(imp, "Select None", ""); + + imp = IJ.getImage().flatten(); + + text = true; + + FinalizePC fpc = new FinalizePC(); + AAPC_Var.putFinalizePC(fpc); + + AAPC_Var.hideFinishingTouches(); + + AAPC_Var.showFinalize(); + + } + + private void subjectToggleButtonActionPerformed(java.awt.event.ActionEvent evt) { + + JToggleButton btn = (JToggleButton) evt.getSource(); + + if (btn.isSelected()) { + img.show(); + } else { + img.hide(); + } + + } + + private void pcsToggleButtonActionPerformed(java.awt.event.ActionEvent evt) { + + JToggleButton btn = (JToggleButton) evt.getSource(); + + if (btn.isSelected()) { + pcs.show(); + } else { + pcs.hide(); + } + + } + + private void imjToggleButtonActionPerformed(java.awt.event.ActionEvent evt) { + + JToggleButton btn = (JToggleButton) evt.getSource(); + + if (btn.isSelected()) { + imj.show(); + } else { + imj.hide(); + } + + } + + private void iplToggleButtonActionPerformed(java.awt.event.ActionEvent evt) { + + JToggleButton btn = (JToggleButton) evt.getSource(); + + if (btn.isSelected()) { + ipl.show(); + } else { + ipl.hide(); + } + + } + + private void ipmToggleButtonActionPerformed(java.awt.event.ActionEvent evt) { + + JToggleButton btn = (JToggleButton) evt.getSource(); + + if (btn.isSelected()) { + ipm.show(); + } else { + ipm.hide(); + } + + } + + private void overlayToggleButtonActionPerformed(java.awt.event.ActionEvent evt) { + + JToggleButton btn = (JToggleButton) evt.getSource(); + + if (btn.isSelected()) { + + IJ.run("Hide Overlay", ""); + + } else { + + IJ.run("Show Overlay", ""); + + } + + } + + private void outlineROIToggleButtonActionPerformed(java.awt.event.ActionEvent evt) { + + JToggleButton btn = (JToggleButton) evt.getSource(); + + if (btn.isSelected()) { + + imp.setRoi(outline); + + Roi roi = imp.getRoi(); + roi.setLocation(pcX + outX, pcY + outY); + int pxy = pcX + outX, pcy = pcY + outY; + + IJ.log("pcX = " + pcX + " outX = " + outX + " pcY = " + pcY + " outY = " + outY); + IJ.log("pxy = " + pxy + " pcy = " + pcy); + + } else { + + IJ.run(imp, "Select None", ""); + + } + + } + + private void pixelBorderToggleButtonActionPerformed(java.awt.event.ActionEvent evt) { + + JToggleButton btn = (JToggleButton) evt.getSource(); + + if (btn.isSelected()) { + + ImageProcessor ip = imp.getProcessor(); + + borders = new int[dimOutline][2]; + borderValues = new double[dimOutline]; + + for (int i = 0; i < dimOutline; i++) { + int x = borders[i][0] = allOutlines[i][0] + pcX; + int y = borders[i][1] = allOutlines[i][1] + pcY; + borderValues[i] = ip.getPixel(x, y); + ip.putPixelValue(x, y, 255); + } + + imp.updateAndDraw(); + } else { + + ImageProcessor ip = imp.getProcessor(); + + for (int i = 0; i < dimOutline; i++) { + int x = allOutlines[i][0] + pcX; + int y = allOutlines[i][1] + pcY; + ip.putPixel(x, y, (int) borderValues[i]); + } + + imp.updateAndDraw(); + + } + + } + + private void counterClockwiseButtonActionPerformed(java.awt.event.ActionEvent evt) { + + angle--; + rotateSubject(angle); + + } + + private void clockwiseButtonActionPerformed(java.awt.event.ActionEvent evt) { + } + + private void backButtonActionPerformed(java.awt.event.ActionEvent evt) { + AAPC_Var.hideFinishingTouches(); + AAPC_Var.showWandFrame(); + } + + private void homeButtonActionPerformed(java.awt.event.ActionEvent evt) { + AAPC_Var.hideFinishingTouches(); + AAPC_Var.showPostCard(); + } + + private void justFinishButtonActionPerformed(java.awt.event.ActionEvent evt) { + + IJ.run(imp, "Select None", ""); + + } + + private void clockwiseButtonMousePressed(java.awt.event.MouseEvent evt) { +// 3 + + angle++; + rotateSubject(angle); + + repeatTimer = new Timer(100, new ActionListener() { + + public void actionPerformed(ActionEvent e) { + angle++; + rotateSubject(angle); + } + }); + repeatTimer.setInitialDelay(100); // start repeating only after 1 second + repeatTimer.start(); + + } + + private void counterClockwiseButtonMousePressed(java.awt.event.MouseEvent evt) { + + angle--; + rotateSubject(angle); + + repeatTimer = new Timer(100, new ActionListener() { + + public void actionPerformed(ActionEvent e) { + angle--; + rotateSubject(angle); + } + }); + repeatTimer.setInitialDelay(10); // start repeating only after 1 second + repeatTimer.start(); + + } + + private void clockwiseButtonMouseReleased(java.awt.event.MouseEvent evt) { + + repeatTimer.stop(); + + } + + private void counterClockwiseButtonMouseReleased(java.awt.event.MouseEvent evt) { + + repeatTimer.stop(); + + } + + private void counterClockwiseButtonMouseClicked(java.awt.event.MouseEvent evt) { + } + + private void clockwiseButtonMouseClicked(java.awt.event.MouseEvent evt) { + } + + private void clockwiseButtonKeyPressed(java.awt.event.KeyEvent evt) { + } + + private void clockwiseButtonKeyReleased(java.awt.event.KeyEvent evt) { + } + + private void clockwiseButtonMouseEntered(java.awt.event.MouseEvent evt) { + } + + private void clockwiseButtonStateChanged(javax.swing.event.ChangeEvent evt) { + } + + public void rotateSubject(int a) { + + IJ.run("Rotate...", "angle=" + a); + IJ.run(imp, "Rotate... ", "angle=" + a + + " grid=1 interpolation=Bilinear"); + +// + } + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + + + + + + + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(FinishingTouches.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(FinishingTouches.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(FinishingTouches.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(FinishingTouches.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(new Runnable() { + + public void run() { + new FinishingTouches().setVisible(true); + } + }); + } + // Variables declaration - do not modify + private javax.swing.JButton backButton; + private javax.swing.JButton clockwiseButton; + private javax.swing.JButton counterClockwiseButton; + private javax.swing.JButton homeButton; + private javax.swing.JToggleButton imjToggleButton; + private javax.swing.JScrollPane informationScrollPane; + private javax.swing.JTextArea informationTextArea; + private javax.swing.JToggleButton iplToggleButton; + private javax.swing.JToggleButton ipmToggleButton; + private javax.swing.JPanel jPanel1; + private javax.swing.JPanel jPanel2; + private javax.swing.JButton justFinishButton; + private javax.swing.JToggleButton outlineROIToggleButton; + private javax.swing.JToggleButton overlayToggleButton; + private javax.swing.JToggleButton pcsToggleButton; + private javax.swing.JToggleButton pixelBorderToggleButton; + private javax.swing.JToggleButton subjectToggleButton; + private javax.swing.JButton textButton; + // End of variables declaration + + private void startUp() { + + imp = AAPC_Var.getImage(); + img = IJ.getImage(); //AAPC_Var.getSubject(); + + Roi testRoi = AAPC_Var.getROI(); + + int x = AAPC_Var.getPCX(); + int y = AAPC_Var.getPCY(); + int w = (int) AAPC_Var.getPCW(); + int h = (int) AAPC_Var.getPCH(); + + imp.setRoi(testRoi); + + int xloc = 400, yloc = 0; + + moveWindow(imp, xloc, yloc); + + final ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); + + setupRedo(); + + start = true; + finish(); + + } + + public void setupRedo() { + + ImageWindow win = imp.getWindow(); + canvas = win.getCanvas(); + canvas.addMouseListener(this); + canvas.addMouseMotionListener(this); + + int x = pcX + outX; + int y = pcY + outY; + + if (redo) { + imp.setRoi(x, y, outW, outH); + } + + redo = true; + + } + + private void finish() { + + IJ.run("Appearance...", " no antialiased menu=0"); + + IJ.run(img, "Select None", ""); + + int fudge = 1; + + pcs = new Duplicator().run(img); + img.hide(); + + pcs.setTitle("PCsubject"); + + pcs.show(); + + pcX = AAPC_Var.getPCX(); + pcY = AAPC_Var.getPCY(); + + reSize(pcs); + + modifyOutline(pcs); + + outline = clearOutline(pcs); + + if (refresh) { + + pcs.setRoi(outline); + IJ.run(pcs, "Enlarge...", "enlarge=-1"); + IJ.run(pcs, "Clear Outside", ""); + + refresh = false; + + } + + ImagePlus hypot = IJ.createImage("Hypot", "RGB Black", hypotenuse, hypotenuse, 1); + + IJ.run(pcs, "Copy", ""); + IJ.run(hypot, "Paste", ""); + +// placeOverlay(hypot); +// +// angle = 0; +// +// pcs.hide(); +// +// dumpExtraImages(); +// +// Frame[] frame = WindowManager.getNonImageWindows(); +// +// for (int i = 0; i < frame.length; i++) { +// +// String s = "ROI Manager"; +// +// String s0 = frame[i].getTitle(); +// +// if (s0.equalsIgnoreCase(s)) { +// IJ.selectWindow("ROI Manager"); +// IJ.run("Close"); +// } +// +// s = "Results"; +// +// if (s0.equalsIgnoreCase(s)) { +// IJ.selectWindow("Results"); +// IJ.run("Close"); +// } +// } + } + + private void placeOverlay(ImagePlus ip) { + + ImageProcessor isub = ip.getProcessor(); + isub = isub.duplicate(); + int width = isub.getWidth(); + int height = isub.getHeight(); + + // calculate image size to rotate without cutting off subject + int len = (int) Math.sqrt((width) * (width) + (height) * (height)); + + isub = isub.crop(); + +// isub = isub.resize(len, len, true); + isub.setRoi(pcX, pcY, len, len); + + imageRoi = new ImageRoi(pcX, pcY, isub); + imageRoi.setZeroTransparent(true); + + overlay = new Overlay(imageRoi); + imp.setOverlay(overlay); + imp.setRoi(imageRoi); + imp.show(); + + } + + private void setupListener() { + +// img = IJ.getImage(); + ImageWindow win = imp.getWindow(); + ImageCanvas canvas = win.getCanvas(); + canvas.addMouseListener(this); + canvas.addMouseMotionListener(this); + } + + private ImagePlus reSize(ImagePlus ima) { + + Roi PCroi = imp.getRoi(); + + Rectangle PCrec = PCroi.getBounds(); + + pcX = PCrec.x; + pcY = PCrec.y; + + double subw = img.getWidth(); + double subh = img.getHeight(); + + double ht = PCrec.getHeight(); + double wt = (subw / subh) * ht; + + IJ.run(ima, "Size...", "width=" + + wt + " height=" + + ht + " constrain average interpolation=Bilinear"); + + return ima; + + } + + private void modifyOutline(ImagePlus ima) { + + ImageProcessor ip = ima.getProcessor(); + + int w = ima.getWidth(); + int h = ima.getHeight(); + + iter = 1; + + for (int i = 0; i < iter; i++) { + + int count = 0; + + for (int x = 0; x < w; x++) { + for (int y = 0; y < h; y++) { + if (x > 0 && x < (w - 1)) { + int v0 = ip.getPixel(x - 1, y); + int v1 = ip.getPixel(x, y); + int v2 = ip.getPixel(x + 1, y); + + if (v0 == 0 && v1 != 0 && v2 != 0) { + count++; + } + + if (v0 != 0 && v1 != 0 && v2 == 0) { + count++; + } + } + } + } + + int outlineX[] = new int[count]; + int outlineY[] = new int[count]; + int outlineV[] = new int[count]; + int c = 0; + + for (int x = 0; x < w; x++) { + for (int y = 0; y < h; y++) { + if (x > 0 && x < (w - 1)) { + int v0 = ip.getPixel(x - 1, y); + int v1 = ip.getPixel(x, y); + int v2 = ip.getPixel(x + 1, y); + + if (v0 == 0 && v1 != 0 && v2 != 0) { + + outlineX[c] = x; + outlineY[c] = y; + outlineV[c] = v2; + c++; + } + + if (v0 != 0 && v1 != 0 && v2 == 0) { + + outlineX[c] = x; + outlineY[c] = y; + outlineV[c] = v0; + c++; + } + } + } + } + + c = 0; + for (int x = 0; x < w; x++) { + for (int y = 0; y < h; y++) { + + if (c < count && outlineX[c] == x && outlineY[c] == y) { + + ip.putPixel(x, y, 0); + + c++; + } + } + } + + count = 0; + + for (int x = 0; x < w; x++) { + for (int y = 0; y < h; y++) { + if (y > 0 && y < (h - 1)) { + int v0 = ip.getPixel(x, y - 1); + int v1 = ip.getPixel(x, y); + int v2 = ip.getPixel(x, y + 1); + + if (v0 == 0 && v1 != 0 && v2 != 0) { + count++; + } + + if (v0 != 0 && v1 != 0 && v2 == 0) { + count++; + } + } + } + } + + int olX[] = new int[count]; + int olY[] = new int[count]; + int olV[] = new int[count]; + c = 0; + + for (int x = 0; x < w; x++) { + for (int y = 0; y < h; y++) { + if (y > 0 && y < (h - 1)) { + int v0 = ip.getPixel(x, y - 1); + int v1 = ip.getPixel(x, y); + int v2 = ip.getPixel(x, y + 1); + + if (v0 == 0 && v1 != 0 && v2 != 0) { + + outlineX[c] = x; + outlineY[c] = y; + outlineV[c] = v2; + c++; + } + + if (v0 != 0 && v1 != 0 && v2 == 0) { + + outlineX[c] = x; + outlineY[c] = y; + outlineV[c] = v0; + c++; + } + } + } + } + + c = 0; + for (int x = 0; x < w; x++) { + for (int y = 0; y < h; y++) { + + if (c < count && outlineX[c] == x && outlineY[c] == y) { + + ip.putPixel(x, y, 0); + + c++; + } + } + } + } + } + + private Roi clearOutline(ImagePlus ima) { + + imj = new Duplicator().run(ima); + IJ.run(imj, "8-bit", ""); + IJ.setThreshold(imj, 1.0, 255.0); + + IJ.run("Set Measurements...", "area redirect=None decimal=2"); + IJ.run(imj, "Analyze Particles...", + "size=0-Infinity circularity=0.00-1.00 show=Nothing clear record"); + + imj.show(); + + ResultsTable rt = Analyzer.getResultsTable(); + int count = rt.getCounter(); + int maxArea = 0; + + int xs = 0, ys = 0; + + for (int i = 0; i < count; i++) { + + int area = (int) rt.getValue("Area", i); + + if (area > maxArea) { + maxArea = area; + xs = (int) rt.getValue("XStart", i); + ys = (int) rt.getValue("YStart", i); + } + } + + IJ.doWand(xs, ys); + + roiman = RoiManager.getInstance(); + if (roiman == null) { + roiman = new RoiManager(); + } + roiman.runCommand("reset"); + + roiman.addRoi(imj.getRoi()); + roiman.select(imj, 0); + roiman.runCommand("Rename", "outline"); + + IJ.run(ima, "Select None", ""); + roiman.select(ima, 0); + + IJ.run(ima, "Clear Outside", ""); + + Roi ol = ima.getRoi(); + + Rectangle rec = ol.getBounds(); + + outX = rec.x; + outY = rec.y; + outW = (int) rec.getWidth(); + outH = (int) rec.getHeight(); + + ipm = getOutlineXY(ima); + + ipl = getAllInteriorROIs(ima); + + allOutlines = outlinesToArray(ipm, ipl); + + imj.hide(); + ipm.hide(); + ipl.hide(); + + return ol; + } + + private ImagePlus getOutlineXY(ImagePlus ima) { + + Roi ol = ima.getRoi(); + + Rectangle r = ol.getBounds(); + double w = r.getWidth(); + double h = r.getHeight(); + double hypot = Math.sqrt((w * w) + (h * h)); + + hypotenuse = (int) hypot; + + IJ.run(ima, "Select None", ""); + ImagePlus outer = new Duplicator().run(ima); + +// outer.show(); + + outer.setTitle("outer"); + + outer.setRoi(ol); + + IJ.run("Colors...", "foreground=black background=white selection=yellow"); + IJ.run(outer, "Clear", "slice"); + + IJ.run("Colors...", "foreground=black background=black selection=yellow"); + try { + IJ.run(outer, "Enlarge...", "enlarge=-1"); + } catch (Exception e) { + dumpExtraImages(); + } + IJ.run(outer, "Fill", "slice"); + IJ.run(outer, "Select None", ""); + IJ.resetThreshold(outer); + + return outer; + + } + + private ImagePlus getAllInteriorROIs(ImagePlus ima) { + + roiman = RoiManager.getInstance(); + if (roiman == null) { + roiman = new RoiManager(); + } + roiman.runCommand("reset"); + + IJ.run(ima, "Select None", ""); + ImagePlus inner = new Duplicator().run(ima); + + inner.show(); + + inner.setTitle("inner"); + + IJ.run(inner, "8-bit", ""); + IJ.setThreshold(inner, 0, 0); + + IJ.run("Set Measurements...", "area limit redirect=None decimal=2"); + + IJ.run(inner, "Analyze Particles...", + "size=0-Infinity circularity=0.00-1.00 " + + "show=Nothing exclude clear record add"); + + ResultsTable rt = Analyzer.getResultsTable(); + int ct = rt.getCounter(); + + if (ct > 0) { + + roiman.runCommand("Combine"); + + IJ.run("Colors...", "foreground=black background=white selection=yellow"); + try { + IJ.run(inner, "Clear Outside", ""); + } catch (Exception e) { + dumpExtraImages(); + } + try { + IJ.run(inner, "Enlarge...", "enlarge=1"); + } catch (Exception e) { + dumpExtraImages(); + } + IJ.run("Colors...", "foreground=white background=black selection=yellow"); + IJ.run(inner, "Clear Outside", ""); + + IJ.resetThreshold(inner); + IJ.run(inner, "Select None", ""); + roiman.runCommand("Show None"); + } + + return inner; + + } + + private int[][] outlinesToArray(ImagePlus pm, ImagePlus pl) { + + ImageCalculator ic = new ImageCalculator(); + ImagePlus imp3 = ic.run("Add create", pm, pl); + + imp3.show(); + imp3.setTitle("combinedROIs"); + + IJ.run("Set Measurements...", "area perimeter limit redirect=None decimal=2"); + IJ.run(imp3, "Measure", ""); + + ResultsTable rt = Analyzer.getResultsTable(); + int ct = rt.getCounter(); + int n = ct - 1; + + dimOutline = (int) rt.getValue("Area", n); + + int[][] outlineXY = new int[dimOutline][2]; + + int w = imp3.getWidth(); + int h = imp3.getHeight(); + ImageProcessor ip = imp3.getProcessor(); + + int count = 0; + + for (int x = 0; x < w; x++) { + for (int y = 0; y < h; y++) { + int v = ip.getPixel(x, y); + float v0 = ip.getPixelValue(x, y); + if (v0 != 0.0) { + outlineXY[count][0] = x; + outlineXY[count][1] = y; + count++; + + } + } + } + +// imp3.hide(); + + return outlineXY; + + } + + private void setLanguage() { + + String s = null; + + switch (language) { + + case 0: + + s = "1. Click and drag on the subject to change the" + + "\n position." + + "\n2. Click and drag the handles (corners) to change " + + "\nthe size." + + "\n3. To rotate the subject, when the position and" + + "\n size are correct, click the clockwise or" + + "\n counterclockwise buttons." + + "\n4. When complete, click the \"Add a message...\"" + + "\nor \"Just finish...\" button."; + + toInstructionWidow(s, false); +// SetToBackgroundButton.setText("Set To Background"); + break; + + case 1: + + s = "Deutsche Anleitungen"; + toInstructionWidow(s, false); +// SetToBackgroundButton.setText("Hintergrund"); + break; + + case 2: + + s = "Frencais parle vouis?"; + toInstructionWidow(s, false); +// SetToBackgroundButton.setText("mis à fond"); + break; + + case 3: + + s = "istruzioni italiani"; + toInstructionWidow(s, false); +// SetToBackgroundButton.setText("impostato su sfondo"); + break; + + case 4: + + s = "Kiswahili Inastrucions"; + toInstructionWidow(s, false); +// SetToBackgroundButton.setText("kuweka background"); + break; + + } + + } + + private void toInstructionWidow(String s, Boolean go) { + if (go) { + String s1 = informationTextArea.getText(); + String s2 = "\n*******************\n"; + informationTextArea.setText(s1 + s2 + s); + } else { + informationTextArea.setText(s); + } + } + + private void dumpExtraImages() { + + int[] id = WindowManager.getIDList(); + int PCid = imp.getID(); + + int c = WindowManager.getImageCount(); + + for (int i = 0; i < c; i++) { + + IJ.selectWindow(id[i]); + if (id[i] != PCid) { + ImagePlus imj = IJ.getImage(); + imj.hide(); + } + + } + + } + + public void mouseClicked(MouseEvent me) { + } + + public void mousePressed(MouseEvent me) { + + if (spin) { + + angle++; + rotateSubject(angle); + + } + + if (spinback) { + + angle--; + rotateSubject(angle); + + } + } + + public void mouseReleased(MouseEvent me) { + + if (resize && !text) { + + IJ.run("Hide Overlay", ""); + + refresh = true; + + finish(); + + resize = false; + + } + + } + + public void mouseEntered(MouseEvent me) { + } + + public void mouseExited(MouseEvent me) { + } + + public void mouseDragged(MouseEvent me) { + + if (!text && redo) { + resize = true; + } + + } + + public void mouseMoved(MouseEvent me) { + } + + private void moveWindow(ImagePlus impl, int x, int y) { + + impl.getWindow().setLocation(x, y); + + } +} diff --git a/src/main/java/Layers_.java b/src/main/java/Layers_.java new file mode 100644 index 0000000..8a4d1e4 --- /dev/null +++ b/src/main/java/Layers_.java @@ -0,0 +1,122 @@ +import ij.*; +import ij.plugin.filter.PlugInFilter; +import ij.process.*; +import ij.gui.*; +import java.awt.*; +import java.util.*; + +/** Bob Dougherty. + Plugin to combine the slices of a stack from back to front. + Version 0 3/12/2004. */ +/* License: + Copyright (c) 2004, 2005, OptiNav, Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + Neither the name of OptiNav, Inc. nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +public class Layers_ implements PlugInFilter, Runnable { + ImagePlus impStack; + ImageProcessor ipStack; + ImageStack stack; + ImageCanvas icStack; + static int napTime = 100; + boolean done = false; + ImagePlus imp; + ImageCanvas ic; + protected Thread thread; + ImageProcessor ip; + + public int setup(String arg, ImagePlus imp) { + impStack = imp; + return DOES_ALL; + } + + public void run(ImageProcessor ip) { + icStack = impStack.getWindow().getCanvas(); + ipStack = ip; + stack = impStack.getStack(); + createImage(); + thread = new Thread(this, "Layers"); + thread.start(); + } + public void run() { + int i = 0; + while (!done) { + try {Thread.sleep(napTime);} + catch(InterruptedException e) { + break; + } + if ((icStack==null)||(ic==null)){ + break; + } + if ((!icStack.isValid())||(!ic.isValid())){ + break; + } + combine(); + } + } + void combine(){ + int n = impStack.getStackSize(); + ImageProcessor ipStack = stack.getProcessor(1); + ip = ipStack.duplicate(); + //double min = ipStack.getMin(); + //double max = ipStack.getMax(); + if (ip instanceof ColorProcessor){ + ColorBlitter cb = new ColorBlitter((ColorProcessor)ip); + cb.setTransparentColor(Toolbar.getBackgroundColor()); + for (int slice = 2; slice <= n; slice++) + cb.copyBits(stack.getProcessor(slice),0,0,Blitter.COPY_TRANSPARENT); + } else if (ip instanceof FloatProcessor){ + FloatBlitter fb = new FloatBlitter((FloatProcessor)ip); + fb.setTransparentColor(Toolbar.getBackgroundColor()); + for (int slice = 2; slice <= n; slice++) + fb.copyBits(stack.getProcessor(slice),0,0,Blitter.COPY_TRANSPARENT); + } else if (ip instanceof ByteProcessor){ + ByteBlitter bb = new ByteBlitter((ByteProcessor)ip); + bb.setTransparentColor(Toolbar.getBackgroundColor()); + for (int slice = 2; slice <= n; slice++) + bb.copyBits(stack.getProcessor(slice),0,0,Blitter.COPY_TRANSPARENT); + } else if (ip instanceof ShortProcessor){ + ShortBlitter sb = new ShortBlitter((ShortProcessor)ip); + sb.setTransparentColor(Toolbar.getBackgroundColor()); + for (int slice = 2; slice <= n; slice++) + sb.copyBits(stack.getProcessor(slice),0,0,Blitter.COPY_TRANSPARENT); + } + imp.setProcessor(null,ip); + imp.updateAndDraw(); + } + + + void createImage(){ + String title = impStack.getShortTitle(); + ImageProcessor ipStack = impStack.getProcessor(); + imp = new ImagePlus("From_"+title,ipStack.duplicate()); + imp.show(); + ic = imp.getWindow().getCanvas(); + } + +} diff --git a/src/main/java/OutlineSubject.java b/src/main/java/OutlineSubject.java new file mode 100644 index 0000000..1c59017 --- /dev/null +++ b/src/main/java/OutlineSubject.java @@ -0,0 +1,233 @@ +import ij.IJ; +import ij.ImagePlus; +import ij.gui.Roi; +import java.awt.Rectangle; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +/** + * + * @author chris + */ +public class OutlineSubject extends javax.swing.JFrame { + + /** + * Creates new form OutlineSubject + */ + public OutlineSubject() { + initComponents(); + + language = AAPC_Var.getLanguage(); + + setLanguage(); + + img = IJ.getImage(); + + IJ.setTool("freehand"); + IJ.run(img, "Select None", ""); + IJ.run("Colors...", "foreground=white background=black selection=red"); + + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // + private void initComponents() { + + outlineSubjectPanel = new javax.swing.JPanel(); + jScrollPane1 = new javax.swing.JScrollPane(); + instructionTextArea = new javax.swing.JTextArea(); + continueButton = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); + setBackground(new java.awt.Color(31, 73, 125)); + + outlineSubjectPanel.setBackground(new java.awt.Color(51, 51, 255)); + + instructionTextArea.setBackground(new java.awt.Color(50, 150, 255)); + instructionTextArea.setColumns(20); + instructionTextArea.setRows(5); + jScrollPane1.setViewportView(instructionTextArea); + + continueButton.setFont(new java.awt.Font("Comic Sans MS", 0, 13)); // NOI18N + continueButton.setText("Continue..."); + continueButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + continueButtonActionPerformed(evt); + } + }); + + org.jdesktop.layout.GroupLayout outlineSubjectPanelLayout = new org.jdesktop.layout.GroupLayout(outlineSubjectPanel); + outlineSubjectPanel.setLayout(outlineSubjectPanelLayout); + outlineSubjectPanelLayout.setHorizontalGroup( + outlineSubjectPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(outlineSubjectPanelLayout.createSequentialGroup() + .addContainerGap() + .add(continueButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 183, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) + .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 465, Short.MAX_VALUE) + ); + outlineSubjectPanelLayout.setVerticalGroup( + outlineSubjectPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(outlineSubjectPanelLayout.createSequentialGroup() + .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 151, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(continueButton) + .addContainerGap(17, Short.MAX_VALUE)) + ); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(outlineSubjectPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(outlineSubjectPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + pack(); + }// + + private void continueButtonActionPerformed(java.awt.event.ActionEvent evt) { + + if (img.getRoi() != null) { + + Roi roi = img.getRoi(); + + Rectangle rec = roi.getBounds(); + + int x = rec.x; + int y = rec.y; + int w = rec.width; + int h = rec.height; + + img.setRoi(x, y, w, h); + + IJ.run(img, "Crop", ""); + + AAPC_Var.hideOutlineSubject(); + + WandFrame wf = new WandFrame(); + wf.setVisible(true); + + AAPC_Var.setWandFrame(wf); + + } else { + IJ.error("You must first outline the subject before isolation"); + } + + } + + private void setLanguage() { + + String s; + + switch (language) { + + case 0: + + s = "Outline the subject, then click continue."; + + toInstructionWidow(s, false); + continueButton.setText("Continue..."); + break; + + case 1: + + s = "Skizzieren Sie das Thema und klicken Sie auf weiter."; + toInstructionWidow(s, false); + continueButton.setText("Weiter..."); + break; + + case 2: + + s = "Décrivez l'objet, puis cliquez sur continuer."; + toInstructionWidow(s, false); + continueButton.setText("Continuer..."); + break; + + case 3: + + s = "Delineare il soggetto, quindi su Continua."; + toInstructionWidow(s, false); + continueButton.setText("Continuare..."); + break; + + case 4: + + s = "Kiswahili Inastrucions"; + toInstructionWidow(s, false); + continueButton.setText("ugh..."); + break; + + } + + } + + private void toInstructionWidow(String s, Boolean go) { + if (go) { + String s1 = instructionTextArea.getText(); + String s2 = "\n*******************\n"; + instructionTextArea.setText(s1 + s2 + s); + } else { + instructionTextArea.setText(s); + } + } + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(OutlineSubject.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(OutlineSubject.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(OutlineSubject.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(OutlineSubject.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new OutlineSubject().setVisible(true); + } + }); + } + // Variables declaration - do not modify + private javax.swing.JButton continueButton; + private javax.swing.JTextArea instructionTextArea; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JPanel outlineSubjectPanel; + // End of variables declaration + // global variables + ImagePlus img; + int language; +} diff --git a/src/main/java/PickSubject.java b/src/main/java/PickSubject.java new file mode 100644 index 0000000..2265077 --- /dev/null +++ b/src/main/java/PickSubject.java @@ -0,0 +1,285 @@ +import ij.IJ; +import ij.ImagePlus; +import ij.gui.ImageWindow; +import ij.gui.Roi; +import ij.io.OpenDialog; +import ij.plugin.Duplicator; +import java.awt.Rectangle; + +/* + * PickSubject.java + * + * Created on Jul 4, 2012, 9:26:25 AM + */ +/** + * Copyright Jun 7, 2012 The GAIA Group + * http://gaiag.net + * + * @author chris + */ +public class PickSubject extends javax.swing.JFrame { + + /** Creates new form PickSubject */ + public PickSubject() { + initComponents(); + + imp = IJ.getImage(); +// IJ.setTool("rectangle"); + + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // + private void initComponents() { + + jPanel1 = new javax.swing.JPanel(); + connectLabel = new javax.swing.JLabel(); + connect2Label = new javax.swing.JLabel(); + connect2Label1 = new javax.swing.JLabel(); + subjectButton = new javax.swing.JButton(); + backButton = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); + setBackground(new java.awt.Color(0, 0, 255)); + + jPanel1.setBackground(new java.awt.Color(51, 51, 255)); + + connectLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 24)); // NOI18N + connectLabel.setForeground(new java.awt.Color(255, 255, 255)); + connectLabel.setText("Please connect a data device "); + + connect2Label.setFont(new java.awt.Font("Comic Sans MS", 0, 18)); // NOI18N + connect2Label.setForeground(new java.awt.Color(255, 255, 255)); + connect2Label.setText("(e.g., USB-stick, SB card)"); + + connect2Label1.setFont(new java.awt.Font("Comic Sans MS", 0, 24)); // NOI18N + connect2Label1.setForeground(new java.awt.Color(255, 255, 255)); + connect2Label1.setText("Then click the subject button."); + + subjectButton.setFont(new java.awt.Font("Comic Sans MS", 0, 24)); // NOI18N + subjectButton.setText("Subject"); + subjectButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + subjectButtonActionPerformed(evt); + } + }); + + backButton.setFont(new java.awt.Font("Comic Sans MS", 0, 24)); // NOI18N + backButton.setText("Back"); + backButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + backButtonActionPerformed(evt); + } + }); + + org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1); + jPanel1.setLayout(jPanel1Layout); + jPanel1Layout.setHorizontalGroup( + jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jPanel1Layout.createSequentialGroup() + .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jPanel1Layout.createSequentialGroup() + .add(21, 21, 21) + .add(connectLabel) + .add(5, 5, 5) + .add(connect2Label)) + .add(jPanel1Layout.createSequentialGroup() + .add(3, 3, 3) + .add(connect2Label1))) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .add(jPanel1Layout.createSequentialGroup() + .add(15, 15, 15) + .add(subjectButton) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(backButton) + .add(34, 34, 34)) + ); + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jPanel1Layout.createSequentialGroup() + .add(5, 5, 5) + .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(connectLabel) + .add(jPanel1Layout.createSequentialGroup() + .add(4, 4, 4) + .add(connect2Label))) + .add(9, 9, 9) + .add(connect2Label1) + .add(22, 22, 22) + .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(subjectButton) + .add(backButton)) + .addContainerGap()) + ); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap()) + ); + + pack(); + }// + + private void subjectButtonActionPerformed(java.awt.event.ActionEvent evt) { + + AAPC_Var.hidePicSubject(); + + OpenDialog opendialog = new OpenDialog("Select image containing the subject.", ""); + + if (opendialog.getFileName() == null) { + return; + } + + String s2 = opendialog.getDirectory(); + String s3 = opendialog.getFileName(); + + ImagePlus img = IJ.openImage(s2 + s3); + + int k = s3.lastIndexOf('.'); + + IJ.run(img, "Set Scale...", "distance=0 known=0 pixel=1 unit=pixel"); + + img = setupSubject(img); + + img.show(); + + ImageWindow iw = new ImageWindow(img); + + iw.maximize(); + + moveWindow(img, 600, 0); + + OutlineSubject os = new OutlineSubject(); + os.setVisible(true); + + AAPC_Var.setOutlineSubject(os); + + } + + private ImagePlus setupSubject(ImagePlus ip) { + + ImagePlus ims = new Duplicator().run(ip); + + ims.setTitle("Subject"); + +// imp = AAPC_Var.getImage(); + + moveWindow(imp, 400, 0); + + imp.setRoi(1126, 181, 343, 975); + + AAPC_Var.setROI(imp.getRoi()); + + Roi PCroi = imp.getRoi(); + + Rectangle PCrec = PCroi.getBounds(); + + int pcX = PCrec.x; + AAPC_Var.setPCX(pcX); + + int pcY = PCrec.y; + AAPC_Var.setPCY(pcY); + + double pcW = PCrec.getWidth(); + AAPC_Var.setPCW(pcW); + + double pcH = PCrec.getHeight(); + AAPC_Var.setPCH(pcH); + + int subw = ims.getWidth(); + int subh = ims.getHeight(); + + double ht = PCrec.getHeight(); + double wt = (double) (subw / subh) * ht; + + IJ.run(ims, "Size...", "width=" + + wt + " height=" + + ht + " constrain average interpolation=Bilinear"); + + IJ.run(imp, "Select None", ""); + + return ims; + + } + + private void moveWindow(ImagePlus impl, int x, int y) { + + impl.getWindow().setLocation(x, y); + + } + + private void backButtonActionPerformed(java.awt.event.ActionEvent evt) { + + AAPC_Var.hidePicSubject(); + AAPC_Var.showYourImage(); + imp.hide(); + + } + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(PickSubject.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(PickSubject.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(PickSubject.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(PickSubject.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(new Runnable() { + + @Override + public void run() { + new PickSubject().setVisible(true); + } + }); + } + // Variables declaration - do not modify + private javax.swing.JButton backButton; + private javax.swing.JLabel connect2Label; + private javax.swing.JLabel connect2Label1; + private javax.swing.JLabel connectLabel; + private javax.swing.JPanel jPanel1; + private javax.swing.JButton subjectButton; + // End of variables declaration + + // Global variables + + ImagePlus imp; +} + diff --git a/src/main/java/PostCard.java b/src/main/java/PostCard.java new file mode 100644 index 0000000..7169497 --- /dev/null +++ b/src/main/java/PostCard.java @@ -0,0 +1,474 @@ +import ij.IJ; +import ij.ImagePlus; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Toolkit; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import javax.imageio.ImageIO; + +/* + * NewIdeas.java + * + * Created on Jun 16, 2012, 10:09:13 AM + */ +/** + * Copyright Jun 7, 2012 The GAIA Group + * http://gaiag.net + * + * @author chris + */ +public class PostCard extends javax.swing.JFrame { + + /** Creates new form NewIdeas */ + public PostCard() { + + screen = Toolkit.getDefaultToolkit().getScreenSize(); + screenHeight = screen.height; + screenWidth = screen.width; + + initComponents(); + + IJ.run("Misc...", "divide=Infinity require"); + + setLabels(); + + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // + private void initComponents() { + + postcardPanel = new javax.swing.JPanel(); + EnglandLabel = new javax.swing.JLabel(); + GermanLabel = new javax.swing.JLabel(); + FranceLabel = new javax.swing.JLabel(); + TitleLabel = new javax.swing.JLabel(); + ItalyLabel = new javax.swing.JLabel(); + createOwnCardButton = new javax.swing.JButton(); + pic1Label = new javax.swing.JLabel(); + putOwnImageButton = new javax.swing.JButton(); + pic2Label = new javax.swing.JLabel(); + figureJButton = new javax.swing.JButton(); + spainLabel = new javax.swing.JLabel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); + setBackground(new java.awt.Color(51, 51, 255)); + setFont(new java.awt.Font("Comic Sans MS", 0, 14)); // NOI18N + setSize(screenWidth, screenHeight + ); + + postcardPanel.setBackground(new java.awt.Color(51, 51, 255)); + + EnglandLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/English.jpg"))); // NOI18N + EnglandLabel.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + EnglishLanguageClicked(evt); + } + }); + + GermanLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/German.jpg"))); // NOI18N + GermanLabel.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + GermanLanguageClicked(evt); + } + }); + + FranceLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/France.jpg"))); // NOI18N + FranceLabel.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + frenchLanguageClicked(evt); + } + }); + + TitleLabel.setBackground(new java.awt.Color(31, 73, 125)); + TitleLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 36)); // NOI18N + TitleLabel.setForeground(new java.awt.Color(230, 224, 236)); + TitleLabel.setText("Create your own post card in just a few minutes!"); + + ItalyLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Italy.jpg"))); // NOI18N + ItalyLabel.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + ItalianLanguageClicked(evt); + } + }); + + createOwnCardButton.setBackground(new java.awt.Color(79, 129, 189)); + createOwnCardButton.setFont(new java.awt.Font("Comic Sans MS", 0, 24)); // NOI18N + createOwnCardButton.setForeground(new java.awt.Color(230, 224, 236)); + createOwnCardButton.setText("Create a postcard from up to 4 of your own pictures"); + createOwnCardButton.setBorderPainted(false); + createOwnCardButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + createOwnCardButtonActionPerformed(evt); + } + }); + + pic1Label.setBackground(new java.awt.Color(31, 73, 125)); + pic1Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pic1canada.jpg"))); // NOI18N + pic1Label.setMaximumSize(new java.awt.Dimension(650, 540)); + pic1Label.setMinimumSize(new java.awt.Dimension(650, 540)); + pic1Label.setPreferredSize(new java.awt.Dimension(650, 540)); + pic1Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + pic1MouseClicked(evt); + } + }); + + putOwnImageButton.setBackground(new java.awt.Color(79, 129, 189)); + putOwnImageButton.setFont(new java.awt.Font("Comic Sans MS", 0, 24)); // NOI18N + putOwnImageButton.setForeground(new java.awt.Color(230, 224, 236)); + putOwnImageButton.setText("Put your own image into one of our postcard templates"); + putOwnImageButton.setBorderPainted(false); + putOwnImageButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + putOwnImageButtonActionPerformed(evt); + } + }); + + pic2Label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + pic2Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pic2koln.jpg"))); // NOI18N + pic2Label.setVerticalAlignment(javax.swing.SwingConstants.TOP); + pic2Label.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT); + pic2Label.setMaximumSize(new java.awt.Dimension(650, 540)); + pic2Label.setMinimumSize(new java.awt.Dimension(650, 540)); + pic2Label.setPreferredSize(new java.awt.Dimension(1920, 1080)); + pic2Label.setVerifyInputWhenFocusTarget(false); + pic2Label.setVerticalTextPosition(javax.swing.SwingConstants.TOP); + pic2Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + pic2MouseClicked(evt); + } + }); + + figureJButton.setBackground(new java.awt.Color(79, 129, 189)); + figureJButton.setFont(new java.awt.Font("Comic Sans MS", 0, 24)); // NOI18N + figureJButton.setText("Use FigureJ"); + figureJButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + figureJButtonActionPerformed(evt); + } + }); + + spainLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/spanish.jpg"))); // NOI18N + spainLabel.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + spanishLanguageClicked(evt); + } + }); + + org.jdesktop.layout.GroupLayout postcardPanelLayout = new org.jdesktop.layout.GroupLayout(postcardPanel); + postcardPanel.setLayout(postcardPanelLayout); + postcardPanelLayout.setHorizontalGroup( + postcardPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(postcardPanelLayout.createSequentialGroup() + .addContainerGap() + .add(postcardPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(postcardPanelLayout.createSequentialGroup() + .add(TitleLabel) + .add(29, 29, 29) + .add(EnglandLabel) + .add(18, 18, 18) + .add(GermanLabel) + .add(18, 18, 18) + .add(FranceLabel) + .add(18, 18, 18) + .add(ItalyLabel) + .add(18, 18, 18) + .add(spainLabel)) + .add(postcardPanelLayout.createSequentialGroup() + .add(postcardPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(pic1Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(createOwnCardButton)) + .add(29, 29, 29) + .add(postcardPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(putOwnImageButton) + .add(pic2Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 799, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))) + .addContainerGap(27, Short.MAX_VALUE)) + .add(postcardPanelLayout.createSequentialGroup() + .add(95, 95, 95) + .add(figureJButton) + .add(0, 0, Short.MAX_VALUE)) + ); + postcardPanelLayout.setVerticalGroup( + postcardPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(postcardPanelLayout.createSequentialGroup() + .add(12, 12, 12) + .add(postcardPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) + .add(postcardPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(EnglandLabel) + .add(TitleLabel) + .add(GermanLabel) + .add(FranceLabel) + .add(ItalyLabel)) + .add(postcardPanelLayout.createSequentialGroup() + .add(spainLabel) + .add(6, 6, 6))) + .add(21, 21, 21) + .add(postcardPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) + .add(pic1Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 465, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(pic2Label, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 539, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(28, 28, 28) + .add(postcardPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(createOwnCardButton) + .add(putOwnImageButton)) + .add(18, 18, 18) + .add(figureJButton) + .addContainerGap(138, Short.MAX_VALUE)) + ); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .add(postcardPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(0, 0, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(postcardPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + pack(); + }// + + private void EnglishLanguageClicked(java.awt.event.MouseEvent evt) { + + language = 0; + + AAPC_Var.setLanguage(language); + + String eng = "Create your own post card in just a few minutes!"; + TitleLabel.setText(eng); + + eng = "Create a postcard from up to 4 of your own pictures"; + createOwnCardButton.setText(eng); + + eng = "Put your own image into one of our postcard templates"; + putOwnImageButton.setText(eng); + + } + + private void GermanLanguageClicked(java.awt.event.MouseEvent evt) { + + language = 1; + + AAPC_Var.setLanguage(language); + + String ger = "Erstellen Sie Ihre Postkarte in nur wenigen Minuten"; + TitleLabel.setText(ger); + + ger = "Postkarte aus bis zu 4 eigenen Fotos erstellen"; + createOwnCardButton.setText(ger); + + ger = "Kreative Karte erstellen aus Vorlage und eigenem Bild"; + putOwnImageButton.setText(ger); + } + + private void createOwnCardButtonActionPerformed(java.awt.event.ActionEvent evt) { + + ourCard(); + + } + + private void putOwnImageButtonActionPerformed(java.awt.event.ActionEvent evt) { + + yourCard(); + + } + + private void frenchLanguageClicked(java.awt.event.MouseEvent evt) { + + language = 2; + + AAPC_Var.setLanguage(language); + + String spa = "French not yet implemented"; + TitleLabel.setText(spa); + + spa = "French not yet implemented"; + createOwnCardButton.setText(spa); + + spa = "French not yet implemented"; + putOwnImageButton.setText(spa); + + } + + private void ItalianLanguageClicked(java.awt.event.MouseEvent evt) { + + language = 3; + + AAPC_Var.setLanguage(language); + + String ita = "Italian not yet implemented"; + TitleLabel.setText(ita); + + ita = "Italian not yet implemented"; + createOwnCardButton.setText(ita); + + ita = "Italian not yet implemented"; + putOwnImageButton.setText(ita); + + } + + private void pic1MouseClicked(java.awt.event.MouseEvent evt) { + + ourCard(); + + } + + private void pic2MouseClicked(java.awt.event.MouseEvent evt) { + + yourCard(); + + } + + private void figureJButtonActionPerformed(java.awt.event.ActionEvent evt) { + + AAPC_Var.hidePostCard(); + + Text_Tool tt = new Text_Tool(); + tt.setVisible(true); + + IJ.run("FigureJ ", ""); + + } + + private void spanishLanguageClicked(java.awt.event.MouseEvent evt) { + + language = 4; + + AAPC_Var.setLanguage(language); + + String spa = "Spanish not yet implemented"; + TitleLabel.setText(spa); + + spa = "Spanish not yet implemented"; + createOwnCardButton.setText(spa); + + spa = "Spanish not yet implemented"; + putOwnImageButton.setText(spa); + + } + + + private BufferedImage image; + + public void ImagePanel() { + + ImagePlus eng = new ImagePlus(); //English.jpg; + + try { + image = ImageIO.read(new File("image name and path")); + } catch (IOException ex) { + // handle exception... + } + } + + public void paintComponent(Graphics g) { + g.drawImage(image, 0, 0, null); // see javadoc for more info on the parameters + + } + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(PostCard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(PostCard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(PostCard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(PostCard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(new Runnable() { + + public void run() { + new PostCard().setVisible(true); + } + }); + } + // Variables declaration - do not modify + private javax.swing.JLabel EnglandLabel; + private javax.swing.JLabel FranceLabel; + private javax.swing.JLabel GermanLabel; + private javax.swing.JLabel ItalyLabel; + private javax.swing.JLabel TitleLabel; + private javax.swing.JButton createOwnCardButton; + private javax.swing.JButton figureJButton; + private javax.swing.JLabel pic1Label; + private javax.swing.JLabel pic2Label; + private javax.swing.JPanel postcardPanel; + private javax.swing.JButton putOwnImageButton; + private javax.swing.JLabel spainLabel; + // End of variables declaration + + // Global Variables + + Dimension screen; + PostCard postc; + int screenHeight; + int screenWidth; + int language = 0; // 0 = English, 1 = Deutsch, 2 = Spanish, 3 = Italian + + void transfer(PostCard pc) { + + postc = pc; + + } + + private void setLabels() { + + pic1Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pic1canada.jpg"))); + pic2Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pic2koln.jpg"))); + + } + + private void ourCard() { + + ChooseCardTemplate cc = new ChooseCardTemplate(); + AAPC_Var.putChooseCardTemplate(cc); + + AAPC_Var.showChooseCard(); + AAPC_Var.hidePostCard(); + + } + + private void yourCard() { + + YourImage yi = new YourImage(); + AAPC_Var.putYourImage(yi); + + AAPC_Var.showYourImage(); + AAPC_Var.hidePostCard(); + + } + +} \ No newline at end of file diff --git a/src/main/java/PrintCard.java b/src/main/java/PrintCard.java new file mode 100644 index 0000000..321912f --- /dev/null +++ b/src/main/java/PrintCard.java @@ -0,0 +1,177 @@ +import ij.IJ; +import ij.ImagePlus; +import ij.macro.Interpreter; +import java.awt.datatransfer.*; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +/** + * + * @author chris + */ +public class PrintCard extends javax.swing.JFrame { + + /** + * Creates new form PrintCard + */ + public PrintCard() { + + initComponents(); + + printNumber = ((Integer) printNumberSpinner.getValue()).intValue(); + Clipboard systemClipboard = null; + try { + systemClipboard = getToolkit().getSystemClipboard(); + } catch (Exception e) { + systemClipboard = null; + } + if (systemClipboard == null) { + IJ.error("Unable to copy to Clipboard."); + return; + } + + String text = Integer.toString(printNumber); + StringSelection contents = new StringSelection(text); + systemClipboard.setContents(contents, contents); + + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // + private void initComponents() { + + doneLabel = new javax.swing.JLabel(); + printButton = new javax.swing.JButton(); + printNumberSpinner = new javax.swing.JSpinner(); + jLabel1 = new javax.swing.JLabel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); + setBackground(new java.awt.Color(31, 73, 125)); + + doneLabel.setBackground(new java.awt.Color(79, 129, 189)); + doneLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 24)); // NOI18N + doneLabel.setForeground(new java.awt.Color(230, 224, 236)); + doneLabel.setText("Your postcard is done!"); + + printButton.setBackground(new java.awt.Color(79, 129, 189)); + printButton.setFont(new java.awt.Font("Comic Sans MS", 0, 18)); // NOI18N + printButton.setText("Print"); + printButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + printButtonActionPerformed(evt); + } + }); + + printNumberSpinner.setFont(new java.awt.Font("Comic Sans MS", 0, 18)); // NOI18N + printNumberSpinner.setModel(new javax.swing.SpinnerNumberModel(1, 1, 100, 1)); + + jLabel1.setBackground(new java.awt.Color(31, 73, 125)); + jLabel1.setFont(new java.awt.Font("Comic Sans MS", 0, 18)); // NOI18N + jLabel1.setForeground(new java.awt.Color(230, 224, 236)); + jLabel1.setText("How many copies?"); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .add(41, 41, 41) + .add(doneLabel) + .addContainerGap()) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .addContainerGap(195, Short.MAX_VALUE) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 161, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(43, 43, 43)) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(printNumberSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 96, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(printButton)) + .add(53, 53, 53)))) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .add(22, 22, 22) + .add(doneLabel) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 42, Short.MAX_VALUE) + .add(jLabel1) + .add(18, 18, 18) + .add(printNumberSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(78, 78, 78) + .add(printButton) + .add(18, 18, 18)) + ); + + pack(); + }// + + private void printButtonActionPerformed(java.awt.event.ActionEvent evt) { + + String cmd = "PrintingPostcard.exe"; + try { + Process p = Runtime.getRuntime().exec(cmd); + } catch (IOException ex) { + Logger.getLogger(PrintCard.class.getName()).log(Level.SEVERE, null, ex); + } + +// ImagePlus imp = IJ.getImage(); +// IJ.run(imp, "Print...", ""); + + } + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(PrintCard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(PrintCard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(PrintCard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(PrintCard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new PrintCard().setVisible(true); + } + }); + } + // Variables declaration - do not modify + private javax.swing.JLabel doneLabel; + private javax.swing.JLabel jLabel1; + private javax.swing.JButton printButton; + private javax.swing.JSpinner printNumberSpinner; + // End of variables declaration + // global variables + int printNumber; + Interpreter interp; +} diff --git a/src/main/java/Text_Tool.java b/src/main/java/Text_Tool.java new file mode 100644 index 0000000..24a4e84 --- /dev/null +++ b/src/main/java/Text_Tool.java @@ -0,0 +1,107 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author chris + */ +public class Text_Tool extends javax.swing.JFrame { + + /** + * Creates new form Text_Tool + */ + public Text_Tool() { + initComponents(); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // + private void initComponents() { + + jButton1 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); + setBackground(new java.awt.Color(31, 73, 125)); + + jButton1.setFont(new java.awt.Font("Comic Sans MS", 0, 24)); // NOI18N + jButton1.setText("Add Text and Finish"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .add(25, 25, 25) + .add(jButton1) + .addContainerGap(27, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .add(24, 24, 24) + .add(jButton1) + .addContainerGap(27, Short.MAX_VALUE)) + ); + + pack(); + }// + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { + + FinalizePC fpc = new FinalizePC(); + AAPC_Var.putFinalizePC(fpc); + + AAPC_Var.showFinalize(); + + } + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(Text_Tool.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(Text_Tool.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(Text_Tool.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(Text_Tool.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new Text_Tool().setVisible(true); + } + }); + } + // Variables declaration - do not modify + private javax.swing.JButton jButton1; + // End of variables declaration +} diff --git a/src/main/java/Versatile_Wand.java b/src/main/java/Versatile_Wand.java new file mode 100644 index 0000000..176b3f3 --- /dev/null +++ b/src/main/java/Versatile_Wand.java @@ -0,0 +1,547 @@ +import ij.*; +import ij.process.*; +import ij.gui.Roi; +import ij.gui.PolygonRoi; +import ij.gui.GenericDialog; +import ij.gui.Wand; +import ij.gui.Toolbar; +import ij.plugin.filter.ExtendedPlugInFilter; +import ij.plugin.filter.PlugInFilterRunner; +import ij.gui.DialogListener; +import ij.plugin.filter.ThresholdToSelection; +import ij.plugin.frame.Recorder; +import ij.plugin.MacroInstaller; +import ij.measure.Calibration; +import java.awt.*; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Set; + + +/** An ImageJ magic wand with selectable tolerance, variable hue or + * grayscale preference for RGB, gradient detection for grayscale, + * 4-connected, 8-connected or disconnected operation and preview. + * + * + * Parameters + * ========== + * + * Value Tolerance: + * The selection is expanded to all image points as long as the difference + * between the pixel value of the point clicked and the image point is + * less than the Value Tolerance. Ignored for thresholded images; there + * the thresholded (red) area is selected instead. For 16-bit and float + * images, note that rounding errors occur, thus the red area displayed + * is only an approximation to the exact thresholded area. In contrast + * to the ImageJ wand, you must click INTO the thresholded area; clicking + * outside will create a beep. + * For color images, see the color slider below. + * The selection can be further restricted by the Gradient Tolerance. + * For calibrated grayscale images, the Gray Value Tolerance is in + * calibrated units (e.g., 'lux'). + * + * Color: + * For RGB images, this slider determines the relative weight of the + * gray value and the color hue/saturation for the evaluation of the + * tolerance. With a value of -100, only the gray value (brightness) is + * taken into account (with weights of the color channels depending on + * the Edit>Options>Conversions>Weighted RGB Conversions checkbox). + * With a value of 0, the vector + * distance between the (unweighted) RGB vectors is used, and with a + * value of 100, only the difference of hue/saturation is taken into + * account, independent of the gray value. Use a large value (e.g. 95) + * if you want to select one color independent of brightness. + * + * Gradient Tolerance: + * Irrespective of the Value Tolerance and color settings, the selection + * is not expanded if the gray level gradient is larger than the Gradient + * Tolerance. + * Gradient tolerance is also active if a threshold is used instead of the + * Value Tolerance; in this case visual inspection is easier with the + * Threshold display in 'Over/Under' mode. + * Gradient detection is less sensitive to noise than in 4-connected mode + * than in 8-connected mode. + * For calibrated images, the gradient tolerance is in calibrated units, + * e.g., 'lux/mm'. For RGB images, gradient tolerance works on the gray + * value only. + * + * Eyedropper Color: + * Uses the ccurrent foreground color (color of the eyedropper tool) as + * reference color (or pixel value), instead of the pixel color (value) + * where the user has clicked. In 4-connected and 8-connected mode (see + * 'connectedness', below) the starting pixel is selected irrespective + * of its color (value). In non-contiguous mode, an empty selection may + * result if no pixel matches the eydropper color within the tolerance. + * + * Connectedness: + * Can be "Eight-Connected", "Four_Connected" or "Non-Contiguous": + * In Eight-Connected mode, the selection proceeds to neighboring pixels + * touching each other at a side or a corner. Four-Connected means that + * the selection proceeds only to neighboring pixels sharing a side with + * the previous pixel. Non-Contiguous mode selects all pixels of the image + * within the tolerance irrespective of connectedness. In non-contiguous + * mode, the 'Gradient Tolerance' and 'Include Holes' options are ignored. + * + * Include Holes: + * When checking this option, the selection created by this wand operation + * will not have interior holes. Nevertheless, holes may arise from + * combining/subtracting selections with the SHIFT or ALT keys. + * + * Usage + * ===== + * - When called from the plugins menu, the menu provides an option to + * install the tool in the ImageJ Toolbar. This replaces all other custom + * tools, e.g. those from the startup macros. + * - Put the following into your ImageJ/macros/StartupMacros.txt file + * to have the Versatile Wand as a standard tool: + + macro 'Versatile Wand Tool-Cf00Lee55O2233' { + getCursorLoc(x, y, z, flags); + call('Versatile_Wand.mousePressed', x, y); + } + macro 'Versatile Wand Tool Options' { + call('Versatile_Wand.setOptions'); + } + + * Left-click the tool icon for selecting the tool + * Right-click or double-click the tool icon for the options menu + * where the tolerance and other parameters can be selected. + * + * Compilation + * =========== + * Note that there is a line "gd.addHelp..." in showDialog that cannot be + * compiled with ImageJ versions before 1.42p. Remove that line if you are + * running an old version of ImageJ. + * + * Version 1.14, Michael Schmid, 2012-Dec-09: Again Bugfix: RGB tolerance was inconsistent + * Version 1.13, Michael Schmid, 2012-Dec-07: Bugfix RGB tolerance was incorrect (incomplete) + * Version 1.12, Michael Schmid, 2010-Sep-10: Can use eyedropper (foreground) color + * instead of the color (value) of the pixel + * Version 1.11, Michael Schmid, 2009-Jul-10: Color, non-contiguous added. + * NullPointerException fixed. + * + */ + +public class Versatile_Wand implements ExtendedPlugInFilter, DialogListener { + private final static String CLASS_NAME = "Versatile_Wand"; + private final static String[] CONNECTED_STRINGS = new String[] {"8-connected", "4-connected", "non-contiguous"}; + private final static int EIGHT_CONNECTED=0, FOUR_CONNECTED=1, NON_CONTIGUOUS=2; + private final static int UNKNOWN=0, OUTSIDE=1, INSIDE=-1; //mask pixel values + // dialog parameters + static double valueTolerance = 0; + static double gradientTolerance = 0; + static double colorSensitivity = 0; + static int connection = EIGHT_CONNECTED; + static boolean includeHoles = false; + static boolean useEyedropper = false; + static int xStart, yStart; + static boolean doWand; + boolean installTool; //always default off (don't remember) + // + static boolean calledByTool; //disables 'install tool' checkbox + ImagePlus imp; + boolean colorMode; + + public int setup (String arg, ImagePlus imp) { + if (IJ.versionLessThan("1.39a")) return DONE; + return imp==null ? NO_IMAGE_REQUIRED : DOES_ALL | NO_UNDO; + } + + public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) { + this.imp = imp; + int impType = 0; + if (imp != null) impType = imp.getType(); + String grayUnit = "", gradientUnit = ""; + if (imp != null && imp.getCalibration() != null) { + Calibration cal = imp.getCalibration(); + grayUnit = cal.getValueUnit(); + gradientUnit = grayUnit+"/"+cal.getUnit(); + } + GenericDialog gd = new GenericDialog("Versatile Wand Options"); + if (imp!= null && (impType==ImagePlus.COLOR_RGB || (impType==ImagePlus.GRAY8 && imp.getProcessor().getCalibrationTable()==null))) + gd.addSlider("Value Tolerance", 0, 255, valueTolerance); + else + gd.addNumericField("Value Tolerance", valueTolerance, 2, 6, "("+grayUnit+")"); + gd.addSlider("Color: Gray only - Std - Hue only", -100, +100, 100*colorSensitivity); + gd.addNumericField("Gradient Tolerance (0=off)", gradientTolerance, 2, 6, "("+gradientUnit+")"); + gd.addCheckbox("Eyedropper Color (instead of pixel color)", useEyedropper); + gd.addChoice("Connectedness", CONNECTED_STRINGS, CONNECTED_STRINGS[connection]); + gd.addCheckbox("Include Holes", includeHoles); + if (!calledByTool) { + gd.addMessage("---"); + gd.addCheckbox("Install Tool", installTool); + } + if (imp != null) { + gd.addMessage("--- Immediate Operation ---"); + gd.addNumericField("x", xStart, 0, 6, "(raw pixel no.)"); + gd.addNumericField("y", yStart, 0, 6, "(raw pixel no.)"); + gd.addCheckbox("Do Wand on OK", doWand); + gd.addPreviewCheckbox(pfr); //passing pfr makes the filter ready for preview + } + //remove the following line when compiling with an ImageJ version before 1.42p + gd.addHelp("http://imagejdocu.tudor.lu/doku.php?id=plugin:segmentation:versatile_wand:start&dummy=.html"); + gd.addDialogListener(this); //the DialogItemChanged method will be called on user input + gd.showDialog(); + if (!gd.wasOKed()) { //gd.wasCancelled would cause 'Macro Aborted' exception + return DONE; + } + IJ.register(this.getClass()); + if (installTool) installTool(); + return (doWand ? DOES_ALL : DONE) | NO_UNDO; + } + + public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) { + valueTolerance = gd.getNextNumber(); + colorSensitivity = 0.01*gd.getNextNumber(); + gradientTolerance = gd.getNextNumber(); + useEyedropper = gd.getNextBoolean(); + connection = gd.getNextChoiceIndex(); + includeHoles = gd.getNextBoolean(); + if (!calledByTool) { + installTool = gd.getNextBoolean(); + } + if (imp != null) { + xStart = (int)gd.getNextNumber(); + yStart = (int)gd.getNextNumber(); + doWand = gd.getNextBoolean(); + } + return !(gd.invalidNumber() || valueTolerance<0 || colorSensitivity<-1 || colorSensitivity>1 || gradientTolerance<0); + } + + public void run(ImageProcessor ip) { + doWand(imp, xStart, yStart); + } + + //unused, we don't work on stacks + public void setNPasses (int nPasses) {} + + /** This method can be called from a tool macro to do the Wand operation */ + public static void mousePressed(String xString, String yString) { + xStart = Integer.parseInt(xString); + yStart = Integer.parseInt(yString); + ImagePlus imp = WindowManager.getCurrentImage(); + if (imp==null) return; + imp.getWindow().setCursor(Cursor.CROSSHAIR_CURSOR); + new Versatile_Wand().doWand(imp, xStart, yStart); + if (Recorder.record) { + boolean save = Recorder.recordInMacros; + Recorder.recordInMacros = true; + Recorder.record("call", CLASS_NAME+".mousePressed", xStart, yStart); + //Recorder.record("call", CLASS_NAME+".mousePressed\",\""+xStart+"\",\""+yStart); + Recorder.recordInMacros = save; + } + } + + /** Call this method from the tool options macro */ + public static void setOptions() { + //find the menu command calling this plugin + Hashtable realCommandsHash = ij.Menus.getCommands(); + Set realCommandSet = realCommandsHash.keySet(); + for (Iterator i = realCommandSet.iterator(); i.hasNext();) { + String command = (String)i.next(); + String method = (String)realCommandsHash.get(command); + if (method.endsWith(CLASS_NAME)) { + calledByTool = true; + IJ.run(command); + calledByTool = false; + return; + } + } + } + + private void installTool () { + String macro = + "macro 'Versatile Wand Tool-Cf00Lee55O2233' {\n" + + " getCursorLoc(x, y, z, flags);\n" + + " call('"+CLASS_NAME+".mousePressed', x, y);\n"+ + "}\n" + + "macro 'Versatile Wand Tool Options' {\n" + + " call('"+CLASS_NAME+".setOptions');\n"+ + "}"; + new MacroInstaller().install(macro); + } + +//static int temmmmp; + private void doWand(ImagePlus imp, int x0, int y0) { + boolean shiftKeyDown = IJ.shiftKeyDown(); + boolean altKeyDown = IJ.altKeyDown(); + ImageProcessor ip = imp.getProcessor(); + int width = ip.getWidth(); + int height = ip.getHeight(); + + // prepare mask + ByteProcessor maskIp = new ByteProcessor(width, height); + byte[] mPixels = (byte[])maskIp.getPixels(); + // offsets to neighboring pixels in x, y and pixel number + int[] dirXoffset = new int[] { 0, 1, 1, 1, 0, -1, -1, -1 }; + int[] dirYoffset = new int[] { -1, -1, 0, 1, 1, 1, 0, -1, }; + int[] dirOffset = new int[] {-width, -width+1, +1, +width+1, +width, +width-1, -1, -width-1 }; + // pixelPointers array for positions that we have to process; initial size is 4096 = 0x1000 points + int pixelPointerMask = 0xf; //binary AND with this mask gets array index + int[] pixelPointers = new int[pixelPointerMask+1]; + + // Pixel value range + Calibration cal = imp.getCalibration(); + float lowLimit, highLimit; + float grayRef; + Color eyeDropperColor=null; + if (useEyedropper) { + eyeDropperColor = Toolbar.getForegroundColor(); // reference color is eyedropper color + int index = ip.getBestIndex(eyeDropperColor); + float[] calTable = ip.getCalibrationTable(); + grayRef = calTable==null ? index : calTable[index]; + } else + grayRef = ip.getPixelValue(x0, y0); // reference color from this pixel + if (ip.getMinThreshold()==ImageProcessor.NO_THRESHOLD) { + lowLimit = grayRef - (float)valueTolerance; + highLimit = grayRef + (float)valueTolerance; + } else if (cal==null) { + lowLimit = (float)ip.getMinThreshold(); + highLimit = (float)ip.getMaxThreshold(); + } else { + lowLimit = (float)cal.getCValue((int)(ip.getMinThreshold()+0.5)); + highLimit = (float)cal.getCValue((int)(ip.getMaxThreshold()+0.5)); + } + if (grayRef < lowLimit || grayRef > highLimit) { + IJ.showStatus("Not in Thresholded Area"); + IJ.beep(); + return; + } + + // Prepare color threshold + colorMode = (ip instanceof ColorProcessor) && colorSensitivity > -1; + int[] rgbPixels = null; + int r0=0, g0=0, b0=0; //rgb of the starting/reference point + double rWeight=0, gWeight=0, bWeight=0; //weights for getting 'parallel' or 'gray' comonent from rgb + if (colorMode) { + rgbPixels = (int[])ip.getPixels(); + if (useEyedropper) { + float[] rgbalpha = eyeDropperColor.getRGBComponents(null); + r0 = (int)(rgbalpha[0]*255+0.5); + g0 = (int)(rgbalpha[1]*255+0.5); + b0 = (int)(rgbalpha[2]*255+0.5); + } else { + int c0 = rgbPixels[x0 + y0*width]; + r0 = (c0>>16)&0xff; + g0 = (c0>>8)&0xff; + b0 = (c0)&0xff; + } + double[] refColor = ((r0==0&&g0==0&&b0==0) || colorSensitivity<=0) ? + ((ColorProcessor)ip).getWeightingFactors() : new double[] {r0, g0, b0}; + normalize(refColor); + rWeight = refColor[0]; + gWeight = refColor[1]; + bWeight = refColor[2]; + } + + // Prepare gradient threshold + boolean useGradient = gradientTolerance>0 && gradientTolerance=lowLimit && v<=highLimit) mPixels[offset] = INSIDE; + } + } + } else { + //queue-based flood fill algorithm + int lastCoord = 0; + int offset0 = x0 + y0*width; + mPixels[offset0] = INSIDE; + pixelPointers[0] = offset0; + for (int iCoord = 0; iCoord<=lastCoord; iCoord++) { + int offset = pixelPointers[iCoord & pixelPointerMask]; + int x = offset % width; + int y = offset / width; + boolean isInner = (x!=0 && y!=0 && x!=(width-1) && y!=(height-1)); + float v = ip.getPixelValue(x,y); + boolean largeGradient = false; + float xGradient=0, yGradient=0; + if (useGradient) { + if (isInner) { + float vpp=ip.getPixelValue(x+1, y+1); + float vpm=ip.getPixelValue(x+1, y-1); + float vmp=ip.getPixelValue(x-1, y+1); + float vmm=ip.getPixelValue(x-1, y-1); + + xGradient = 0.125f*( //Sobel-filter like gradient + 2f*(ip.getPixelValue(x+1, y)-ip.getPixelValue(x-1, y)) + + vpp-vmm +(vpm-vmp)); // v(x+1) - v(x-1) + yGradient = 0.125f*( + 2f*(ip.getPixelValue(x, y+1)-ip.getPixelValue(x, y-1)) + + vpp-vmm -(vpm-vmp)); // v(y+1) - v(y-1) + } else { + int xCount=0, yCount=0; + for (int d=0; d<8; d++) if (isWithin(ip, x, y, d)) { + int x2 = x+dirXoffset[d]; + int y2 = y+dirYoffset[d]; + float v2 = ip.getPixelValue(x2, y2); + int weight = (2-(d&0x1)); //2 for straight, 1 for diag + xGradient += dirXoffset[d] * (v2-v) * weight; + xCount += weight * (dirXoffset[d]!=0 ? 1 : 0); + yGradient += dirYoffset[d] * (v2-v) * weight; + yCount += weight * (dirYoffset[d]!=0 ? 1 : 0); + } + xGradient /= xCount; + yGradient /= yCount; + } + largeGradient = xGradient*xGradient + yGradient*yGradient*aspectRatioSqr > toleranceGrayGrad2; + } + for (int d=0; d<8; d+= (connection==FOUR_CONNECTED)?2:1) { //analyze all neighbors (in 4 or 8 directions) + int offset2 = offset+dirOffset[d]; + if ((isInner || isWithin(ip, x, y, d)) && mPixels[offset2] == UNKNOWN) { + int x2 = x+dirXoffset[d]; + int y2 = y+dirYoffset[d]; + float v2 = 0; + boolean valueOK; + if (largeGradient || !colorMode) + v2 = ip.getPixelValue(x2, y2); + if (colorMode) { + int c2 = rgbPixels[offset2]; + valueOK = checkColor(c2, r0, g0, b0, rWeight, gWeight, bWeight); + } else // if !colorMode + valueOK = v2>=lowLimit && v2<=highLimit; + if (!valueOK) { + mPixels[offset2] = OUTSIDE; //don't analyze any more + } else if (!largeGradient || (v2-v)*(xGradient*dirXoffset[d]+yGradient*dirYoffset[d])<=0) { + mPixels[offset2] = INSIDE; //add new point + if (ymin > y2) ymin = y2; + if (lastCoord-iCoord > pixelPointerMask) { //not enough space in array, expand it + int newSize = 2*(pixelPointerMask+1); + int newMask = newSize - 1; + int[] newPixelPointers = new int[newSize]; + System.arraycopy(pixelPointers, 0, newPixelPointers, 0, pixelPointerMask+1); + System.arraycopy(pixelPointers, 0, newPixelPointers, pixelPointerMask+1, pixelPointerMask+1); + pixelPointers = newPixelPointers; + pixelPointerMask = newMask; + } + lastCoord++; + pixelPointers[lastCoord & pixelPointerMask] = offset2; + + } + } + } //for direction d + if ((iCoord&0xfff)==1) { + IJ.showProgress(iCoord/(double)(width*height)); + if (Thread.currentThread().isInterrupted()) return; + } + } //for iCoord + } //else: if contiguous + + Roi previousRoi = imp.getRoi(); + //convert mask to roi + Roi roi = null; + if (includeHoles && connection!=NON_CONTIGUOUS) { + Wand w = new Wand(maskIp); + w.autoOutline(0, ymin, 255, 255); //starting at x0, y0 might trace an inner hole + if (w.npoints>0) { + roi = new PolygonRoi(w.xpoints, w.ypoints, w.npoints, Roi.TRACED_ROI); + if (Thread.currentThread().isInterrupted()) return; + imp.killRoi(); + imp.setRoi(roi); + } + } else { + maskIp.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE); + if (Thread.currentThread().isInterrupted()) return; + imp.killRoi(); + ThresholdToSelection tts = new ThresholdToSelection(); + tts.setup("", imp); + tts.run(maskIp); + roi = imp.getRoi(); + } + + // add/subtract this ROI to the previous one if the shift/alt key is down + if (Thread.currentThread().isInterrupted()) return; + if (roi!=null && previousRoi!=null) + roi.update(shiftKeyDown, altKeyDown); + + IJ.showProgress(1.0); + } + + /** Returns whether pixel with rgb is inside color tolerance */ + boolean checkColor(int rgb, int r0, int g0, int b0, double rWeight, double gWeight, double bWeight) { + int deltaR = ((rgb>>16)&0xff) - r0; + int deltaG = ((rgb>>8)&0xff) - g0; + int deltaB = ((rgb)&0xff) - b0; + double deltaSqr = (1./3.)*(deltaR*deltaR + deltaG*deltaG + deltaB*deltaB); +//if(temmmmp==253740)IJ.log("cSens="+(float)colorSensitivity+" dR="+deltaR+" dG="+deltaG+" dB="+deltaB); +//if(temmmmp==253740)IJ.log("rWeight="+rWeight+" gWeight="+gWeight+" bWeight="+bWeight); + if (colorSensitivity==0) + return deltaSqr <= valueTolerance*valueTolerance; + else { + double deltaPar = deltaR*rWeight + deltaG*gWeight + deltaB*bWeight; + double deltaParSqr = deltaPar*deltaPar; + // we want the following weighting of delta-squared parallel and perpendicular components: + // parallel + (1+colorSensitivity)*perpendicular if colorSensitivity <0, + // parallel*(1-colorSensitivity) + perpendicular if colorSensitivity >0 + // The perpendicular component is deltaSqr - deltaParSqr. +//if(temmmmp==253740)IJ.log("deltaSqr="+(float)deltaSqr+" deltaParSqr="+(float)deltaParSqr+" cSens="+(float)colorSensitivity); + if (colorSensitivity <0) + return deltaSqr*(1.+colorSensitivity) - deltaParSqr*colorSensitivity <= valueTolerance*valueTolerance; + else + return deltaSqr - deltaParSqr*colorSensitivity <= valueTolerance*valueTolerance; + } + } + + /** Returns whether the neighbor in a given direction is within the image + * NOTE: it is assumed that the pixel x,y itself is within the image! + * Uses class variables width, height: dimensions of the image + * @param x x-coordinate of the pixel that has a neighbor in the given direction + * @param y y-coordinate of the pixel that has a neighbor in the given direction + * @param direction the direction from the pixel towards the neighbor (see makeDirectionOffsets) + * @return true if the neighbor is within the image (provided that x, y is within) + */ + boolean isWithin(ImageProcessor ip, int x, int y, int direction) { + int width = ip.getWidth(); + int height = ip.getHeight(); + int xmax = width - 1; + int ymax = height -1; + switch(direction) { + case 0: + return (y>0); + case 1: + return (x0); + case 2: + return (x0 && y0); + case 7: + return (x>0 && y>0); + } + return false; //should never occur, we use it only for directions 0-7 + } // isWithin + + /* normalize 3-element vector */ + void normalize (double[] v) { + double norm = 1./Math.sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]); + for (int i=0; i<3; i++) + v[i] *= norm; + //IJ.log("weights:"+(float)v[0]+","+(float)v[1]+","+(float)v[2]); + } + +} diff --git a/src/main/java/WandFrame.java b/src/main/java/WandFrame.java new file mode 100644 index 0000000..a690c3a --- /dev/null +++ b/src/main/java/WandFrame.java @@ -0,0 +1,677 @@ +import ij.IJ; +import ij.ImagePlus; +import ij.gui.ImageCanvas; +import ij.gui.ImageWindow; +import ij.gui.Overlay; +import ij.gui.Roi; +import ij.plugin.frame.RoiManager; +import ij.process.ImageProcessor; +import java.awt.Color; +import java.awt.Rectangle; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; + +/* + * WandFrame.java + * + * Created on May 14, 2012, 5:06:16 PM + */ +/** + * Copyright Jun 7, 2012 The GAIA Group + * http://gaiag.net + * + * @author chris + */ +public final class WandFrame extends javax.swing.JFrame + implements MouseListener, MouseMotionListener { + + /** Creates new form WandFrame */ + public WandFrame() { + + initComponents(); + + start = true; + + language = AAPC_Var.getLanguage(); + + setLanguage(); + + img = IJ.getImage(); + + IJ.run("Colors...", "foreground=white background=black selection=red"); + + if (start) { + setupListener(); + + start = false; + } + +// IJ.setTool("freehand"); +// IJ.run(img, "Select None", ""); + + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // + private void initComponents() { + + wandFramePanel = new javax.swing.JPanel(); + ToleranceSlider = new javax.swing.JSlider(); + SetToBackgroundButton = new javax.swing.JButton(); + KillSelectionButton = new javax.swing.JButton(); + jScrollPane1 = new javax.swing.JScrollPane(); + InstructionTextArea = new javax.swing.JTextArea(); + toPostCardButton = new javax.swing.JButton(); + backButton = new javax.swing.JButton(); + homeButton = new javax.swing.JButton(); + ColorSlider = new javax.swing.JSlider(); + GradientSlider = new javax.swing.JSlider(); + + setBackground(new java.awt.Color(0, 0, 255)); + + wandFramePanel.setBackground(new java.awt.Color(51, 51, 255)); + + ToleranceSlider.setForeground(new java.awt.Color(255, 255, 255)); + ToleranceSlider.setMajorTickSpacing(10); + ToleranceSlider.setMinorTickSpacing(1); + ToleranceSlider.setPaintLabels(true); + ToleranceSlider.setPaintTicks(true); + ToleranceSlider.setSnapToTicks(true); + ToleranceSlider.setValue(90); + ToleranceSlider.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Tolerance Adjustment", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Comic Sans MS", 0, 14), new java.awt.Color(255, 255, 255))); // NOI18N + ToleranceSlider.addChangeListener(new javax.swing.event.ChangeListener() { + public void stateChanged(javax.swing.event.ChangeEvent evt) { + WandStateChanged(evt); + } + }); + + SetToBackgroundButton.setFont(new java.awt.Font("Comic Sans MS", 0, 14)); // NOI18N + SetToBackgroundButton.setText("Set To Background"); + SetToBackgroundButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + SetToBackgroundButtonActionPerformed(evt); + } + }); + + KillSelectionButton.setFont(new java.awt.Font("Comic Sans MS", 0, 14)); // NOI18N + KillSelectionButton.setText("Kill Selection"); + KillSelectionButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + KillSelectionButtonActionPerformed(evt); + } + }); + + jScrollPane1.setBackground(new java.awt.Color(50, 150, 255)); + + InstructionTextArea.setEditable(false); + InstructionTextArea.setBackground(new java.awt.Color(50, 150, 255)); + InstructionTextArea.setColumns(20); + InstructionTextArea.setFont(new java.awt.Font("Comic Sans MS", 0, 14)); // NOI18N + InstructionTextArea.setForeground(new java.awt.Color(255, 255, 255)); + InstructionTextArea.setLineWrap(true); + InstructionTextArea.setRows(5); + InstructionTextArea.setText("1. Drag the slider back or forth until the background is subtracted \n without any subject.\n2. Click the 'Set To Background' button.\n3. Repeat for all remaining background areas.\n4. To complete the postcard, click the 'To Postcard' button."); + InstructionTextArea.setBorder(javax.swing.BorderFactory.createEmptyBorder(4, 4, 4, 4)); + jScrollPane1.setViewportView(InstructionTextArea); + + toPostCardButton.setFont(new java.awt.Font("Comic Sans MS", 0, 14)); // NOI18N + toPostCardButton.setText("To Postcard"); + toPostCardButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + toPostCardButtonActionPerformed(evt); + } + }); + + backButton.setFont(new java.awt.Font("Comic Sans MS", 0, 14)); // NOI18N + backButton.setText("Back"); + backButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + backButtonActionPerformed(evt); + } + }); + + homeButton.setFont(new java.awt.Font("Comic Sans MS", 0, 14)); // NOI18N + homeButton.setText("Home"); + homeButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + homeButtonActionPerformed(evt); + } + }); + + ColorSlider.setForeground(new java.awt.Color(255, 255, 255)); + ColorSlider.setMajorTickSpacing(10); + ColorSlider.setMinorTickSpacing(1); + ColorSlider.setPaintLabels(true); + ColorSlider.setPaintTicks(true); + ColorSlider.setSnapToTicks(true); + ColorSlider.setValue(75); + ColorSlider.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Color Adjustment", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Comic Sans MS", 0, 14), new java.awt.Color(255, 255, 255))); // NOI18N + ColorSlider.addChangeListener(new javax.swing.event.ChangeListener() { + public void stateChanged(javax.swing.event.ChangeEvent evt) { + ColorSliderWandStateChanged(evt); + } + }); + + GradientSlider.setForeground(new java.awt.Color(255, 255, 255)); + GradientSlider.setMajorTickSpacing(10); + GradientSlider.setMinorTickSpacing(1); + GradientSlider.setPaintLabels(true); + GradientSlider.setPaintTicks(true); + GradientSlider.setSnapToTicks(true); + GradientSlider.setValue(10); + GradientSlider.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Gradient Adjustment", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Comic Sans MS", 0, 14), new java.awt.Color(255, 255, 255))); // NOI18N + GradientSlider.addChangeListener(new javax.swing.event.ChangeListener() { + public void stateChanged(javax.swing.event.ChangeEvent evt) { + GradientSliderWandStateChanged(evt); + } + }); + + org.jdesktop.layout.GroupLayout wandFramePanelLayout = new org.jdesktop.layout.GroupLayout(wandFramePanel); + wandFramePanel.setLayout(wandFramePanelLayout); + wandFramePanelLayout.setHorizontalGroup( + wandFramePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(wandFramePanelLayout.createSequentialGroup() + .addContainerGap() + .add(wandFramePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(wandFramePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false) + .add(wandFramePanelLayout.createSequentialGroup() + .add(backButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 243, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(homeButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .add(toPostCardButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 497, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(wandFramePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false) + .add(org.jdesktop.layout.GroupLayout.LEADING, wandFramePanelLayout.createSequentialGroup() + .add(SetToBackgroundButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 241, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(KillSelectionButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .add(org.jdesktop.layout.GroupLayout.LEADING, GradientSlider, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 495, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(ToleranceSlider, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 495, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(ColorSlider, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 495, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .add(wandFramePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(wandFramePanelLayout.createSequentialGroup() + .addContainerGap() + .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 495, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addContainerGap(8, Short.MAX_VALUE))) + ); + wandFramePanelLayout.setVerticalGroup( + wandFramePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(wandFramePanelLayout.createSequentialGroup() + .add(133, 133, 133) + .add(ColorSlider, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(ToleranceSlider, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(GradientSlider, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(12, 12, 12) + .add(wandFramePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(SetToBackgroundButton) + .add(KillSelectionButton)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(toPostCardButton) + .add(4, 4, 4) + .add(wandFramePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(backButton) + .add(homeButton)) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .add(wandFramePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(wandFramePanelLayout.createSequentialGroup() + .addContainerGap() + .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addContainerGap(380, Short.MAX_VALUE))) + ); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(wandFramePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(wandFramePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + ); + + pack(); + }// + + private void WandStateChanged(javax.swing.event.ChangeEvent evt) { + + if (img.getRoi() != null) { + Roi roi = img.getRoi(); + + int type = roi.getType(); + + if (type == 10) { + + Rectangle rec = roi.getBounds(); + + x0 = rec.x; + y0 = rec.y; + } + + setROI(roi, x0, y0); + + } + } + + private void setROI(Roi roi, int x1, int y1) { + + int tolerance = ToleranceSlider.getValue(); + int colorAdj = ColorSlider.getValue(); + int gradient = GradientSlider.getValue(); + + IJ.run(img, "Select None", ""); + + IJ.run(img, "Versatile Wand", + "value=" + tolerance + + " color=" + colorAdj + + " gradient=" + gradient + " " + + "connectedness=8-connected " + + "x=" + x1 + " y=" + y1 + " do"); + if (start) { + roi = img.getRoi(); + } + + showFill(roi); + + } + + private void SetToBackgroundButtonActionPerformed(java.awt.event.ActionEvent evt) { + + noOutline = true; + +// IJ.run("Colors...", "foreground=white background=black selection=red"); + IJ.run("Colors...", "foreground=white background=black selection=red"); + + if (noOutline) { + IJ.run(img, "Enlarge...", "enlarge=1"); + } + + IJ.run(img, "Clear", "slice"); + + } + + private void KillSelectionButtonActionPerformed(java.awt.event.ActionEvent evt) { + + IJ.run(img, "Select None", ""); + + } + + private void toPostCardButtonActionPerformed(java.awt.event.ActionEvent evt) { + + IJ.run(img, "Versatile Wand", + "value=0 color=0 gradient=0 " + + "connectedness=8-connected x=0 y=0 do"); + IJ.run("Make Inverse", ""); + + Cut_Paste cp = new Cut_Paste(); + cp.setVisible(true); + + AAPC_Var.putSubject(img); + + AAPC_Var.putCutPaste(cp); + + AAPC_Var.hideWandFrame(); + + } + + private void backButtonActionPerformed(java.awt.event.ActionEvent evt) { + + AAPC_Var.hideWandFrame(); + AAPC_Var.showPicSubject(); + + img.hide(); + + } + + private void homeButtonActionPerformed(java.awt.event.ActionEvent evt) { +// put in a close all images here &&& + AAPC_Var.hideWandFrame(); + AAPC_Var.showPostCard(); + + } + + private void ColorSliderWandStateChanged(javax.swing.event.ChangeEvent evt) { + + if (img.getRoi() != null) { + Roi roi = img.getRoi(); + + int type = roi.getType(); + + if (type == 10) { + + Rectangle rec = roi.getBounds(); + + x0 = rec.x; + y0 = rec.y; + } + + int tolerance = ToleranceSlider.getValue(); + int colorAdj = ColorSlider.getValue(); + int gradient = GradientSlider.getValue(); + + IJ.run(img, "Select None", ""); + + //IJ.doWand(x0, y0, tolerance, "8-connected"); + IJ.run(img, "Versatile Wand", + "value=" + tolerance + + " color=" + colorAdj + + " gradient=" + gradient + " " + + "connectedness=8-connected " + + "x=" + x0 + " y=" + y0 + " do"); + + showFill(roi); + + } + } + + private void GradientSliderWandStateChanged(javax.swing.event.ChangeEvent evt) { + + if (img.getRoi() != null) { + Roi roi = img.getRoi(); + + int type = roi.getType(); + + if (type == 10) { + + Rectangle rec = roi.getBounds(); + + x0 = rec.x; + y0 = rec.y; + } + + int tolerance = ToleranceSlider.getValue(); + int colorAdj = ColorSlider.getValue(); + int gradient = GradientSlider.getValue(); + + IJ.run(img, "Select None", ""); + + //IJ.doWand(x0, y0, tolerance, "8-connected"); + IJ.run(img, "Versatile Wand", + "value=" + tolerance + + " color=" + colorAdj + + " gradient=" + gradient + " " + + "connectedness=8-connected " + + "x=" + x0 + " y=" + y0 + " do"); + + showFill(roi); + + } + } + + /** + * + * @param me + */ + @Override + public void mouseClicked(MouseEvent me) { + + int x = me.getX(); + int y = me.getY(); + + int tolerance = ToleranceSlider.getValue(); + int colorAdj = ColorSlider.getValue(); + int gradient = GradientSlider.getValue(); + + x0 = canvas.offScreenX(x); + y0 = canvas.offScreenY(y); + + IJ.run(img, "Select None", ""); + + //IJ.doWand(x0, y0, tolerance, "8-connected"); + IJ.run(img, "Versatile Wand", + "value=" + tolerance + + " color=" + colorAdj + + " gradient=" + gradient + + " connectedness=8-connected " + + "x=" + x0 + " y=" + y0 + " do"); + + + Roi roi = img.getRoi(); + + showFill(roi); + + } + + /** + * + * @param me + */ + @Override + public void mousePressed(MouseEvent me) { + } + + /** + * + * @param me + */ + @Override + public void mouseReleased(MouseEvent me) { + } + + /** + * + * @param me + */ + @Override + public void mouseEntered(MouseEvent me) { + } + + /** + * + * @param me + */ + @Override + public void mouseExited(MouseEvent me) { + } + + /** + * + * @param me + */ + @Override + public void mouseDragged(MouseEvent me) { + } + + /** + * + * @param me + */ + @Override + public void mouseMoved(MouseEvent me) { + } + + public void setupListener() { + + img = IJ.getImage(); + ImageWindow win = img.getWindow(); + canvas = win.getCanvas(); + canvas.addMouseListener(this); + + int mode = img.getStatistics().mode; + + ImageProcessor ip = img.getProcessor(); + + int w = img.getWidth(); + int h = img.getHeight(); + + Boolean stop = true; + + int tolerance = ToleranceSlider.getValue(); + int colorAdj = ColorSlider.getValue(); + int gradient = GradientSlider.getValue(); + + //IJ.run("Wand Tool...", "mode=8-connected tolerance=55"); + //IJ.run(img, "Versatile Wand", "value=70 color=70 gradient=0 connectedness=8-connected x=118 y=226 do"); + + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++) { + if (stop && ip.getPixelValue(x, y) == mode) { + //IJ.doWand(x, y); + IJ.run(img, "Versatile Wand", "value=" + tolerance + + " color=" + colorAdj + + " gradient=" + gradient + " " + + "connectedness=8-connected " + + "x=" + x + " y=" + y + " do"); + + stop = false; + + } + } + } + } + + private void setLanguage() { + + String s; + + switch (language) { + + case 0: + + s = "1. Drag the slider back or forth until the background is subtracted" + + "\n without any subject." + + "\n2. Click the 'Set To Background' button." + + "\n3. Repeat for all remaining background areas." + + "\n4. To complete the postcard, click the 'To Postcard' button."; + + toInstructionWidow(s, false); + SetToBackgroundButton.setText("Set To Background"); + break; + + case 1: + + s = "1. Ziehen Sie den Schieberegler vor oder zurück, bis der Hintergrund ohne Subjekt subtrahiert wird." + + "2. Klicken Sie auf die 'Set To Background'" + + "3. Wiederholen Sie dies für alle übrigen Bereiche Hintergrund." + + "4. Um die Postkarte abzuschließen, klicken Sie auf die 'To-Postkarte'"; + + toInstructionWidow(s, false); + SetToBackgroundButton.setText("Hintergrund"); + break; + + case 2: + + s = "Frencais parle vouis?"; + toInstructionWidow(s, false); + SetToBackgroundButton.setText("mis à fond"); + break; + + case 3: + + s = "istruzioni italiani"; + toInstructionWidow(s, false); + SetToBackgroundButton.setText("impostato su sfondo"); + break; + + case 4: + + s = "Kiswahili Inastrucions"; + toInstructionWidow(s, false); + SetToBackgroundButton.setText("kuweka background"); + break; + + } + + } + + private void showFill(Roi roi) { + + float r = 150 / 255, g = 0 / 255, b = 150 / 255, alpha = (float) 0.5; + + roi.setFillColor(new Color(r, g, b, alpha)); + img.setOverlay(new Overlay(roi)); + + img.updateAndDraw(); + } + + private void toInstructionWidow(String s, Boolean go) { + if (go) { + String s1 = InstructionTextArea.getText(); + String s2 = "\n*******************\n"; + InstructionTextArea.setText(s1 + s2 + s); + } else { + InstructionTextArea.setText(s); + } + } + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(WandFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(WandFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(WandFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(WandFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(new Runnable() { + + @Override + public void run() { + new WandFrame().setVisible(true); + } + }); + } + // Variables declaration - do not modify + private javax.swing.JSlider ColorSlider; + private javax.swing.JSlider GradientSlider; + private javax.swing.JTextArea InstructionTextArea; + private javax.swing.JButton KillSelectionButton; + private javax.swing.JButton SetToBackgroundButton; + private javax.swing.JSlider ToleranceSlider; + private javax.swing.JButton backButton; + private javax.swing.JButton homeButton; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JButton toPostCardButton; + private javax.swing.JPanel wandFramePanel; + // End of variables declaration + // Global Variables + ImagePlus img; + ImageProcessor crop; + int language; + int x0, y0, pcX, pcY, + outX, outY, + iter, rotate, + dimOutline, + outW, outH; + int[][] allOutlines, borders; + double[] borderValues; + boolean noOutline, redo = false, + resize = false, refresh = false, + text = false, start = false, + isolate = false; + ImageCanvas canvas; + Roi outline; + RoiManager roiman; +} \ No newline at end of file diff --git a/src/main/java/YourImage.java b/src/main/java/YourImage.java new file mode 100644 index 0000000..a929adb --- /dev/null +++ b/src/main/java/YourImage.java @@ -0,0 +1,271 @@ +import ij.IJ; +import ij.ImageJ; +import ij.ImagePlus; +import ij.io.Opener; +import java.awt.Image; +import java.awt.Toolkit; +import java.awt.image.ImageProducer; +import java.io.IOException; +import java.io.InputStream; +import java.util.logging.Level; +import java.util.logging.Logger; + +/* + * YourImage.java + * + * Created on Jul 3, 2012, 7:45:53 PM + */ +/** + * Copyright Jun 7, 2012 The GAIA Group http://gaiag.net + * + * @author chris + */ +public class YourImage extends javax.swing.JFrame { + + /** + * Creates new form YourImage + */ + public YourImage() { + initComponents(); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // + private void initComponents() { + + yourImagePanel = new javax.swing.JPanel(); + chooseBackgroundLabel = new javax.swing.JLabel(); + localLabel = new javax.swing.JLabel(); + generalLabel = new javax.swing.JLabel(); + localPic1Label = new javax.swing.JLabel(); + generalPic2Label = new javax.swing.JLabel(); + generalPic1Label = new javax.swing.JLabel(); + localLabel2 = new javax.swing.JLabel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); + setBackground(new java.awt.Color(31, 73, 125)); + setMaximumSize(new java.awt.Dimension(1920, 1080)); + setPreferredSize(new java.awt.Dimension(1920, 1080)); + + yourImagePanel.setBackground(new java.awt.Color(51, 51, 255)); + + chooseBackgroundLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 36)); // NOI18N + chooseBackgroundLabel.setForeground(new java.awt.Color(255, 255, 255)); + chooseBackgroundLabel.setText("Please choose a background:"); + + localLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 24)); // NOI18N + localLabel.setForeground(new java.awt.Color(255, 255, 255)); + localLabel.setText("Local"); + + generalLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 24)); // NOI18N + generalLabel.setForeground(new java.awt.Color(255, 255, 255)); + generalLabel.setText("General"); + + localPic1Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon_sequoia.jpg"))); // NOI18N + localPic1Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + localPic1Clicked(evt); + } + }); + + generalPic2Label.setBackground(new java.awt.Color(31, 73, 125)); + generalPic2Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon_Argonauti.jpg"))); // NOI18N + generalPic2Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + generalPic2Clicked(evt); + } + }); + + generalPic1Label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon_Ostuni.jpg"))); // NOI18N + generalPic1Label.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + generalPic1Clicked(evt); + } + }); + + localLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon_KolnCathedral.jpg"))); // NOI18N + localLabel2.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + localLabel2Clicked(evt); + } + }); + + org.jdesktop.layout.GroupLayout yourImagePanelLayout = new org.jdesktop.layout.GroupLayout(yourImagePanel); + yourImagePanel.setLayout(yourImagePanelLayout); + yourImagePanelLayout.setHorizontalGroup( + yourImagePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(yourImagePanelLayout.createSequentialGroup() + .add(14, 14, 14) + .add(chooseBackgroundLabel) + .addContainerGap(30, Short.MAX_VALUE)) + .add(yourImagePanelLayout.createSequentialGroup() + .add(28, 28, 28) + .add(yourImagePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(localPic1Label) + .add(localLabel2) + .add(generalLabel)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(yourImagePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(generalPic1Label) + .add(generalPic2Label) + .add(localLabel)) + .add(45, 45, 45)) + ); + yourImagePanelLayout.setVerticalGroup( + yourImagePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(yourImagePanelLayout.createSequentialGroup() + .add(5, 5, 5) + .add(chooseBackgroundLabel) + .add(yourImagePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(yourImagePanelLayout.createSequentialGroup() + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(generalLabel) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .add(org.jdesktop.layout.GroupLayout.TRAILING, yourImagePanelLayout.createSequentialGroup() + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(localLabel) + .add(18, 18, 18))) + .add(yourImagePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, localPic1Label) + .add(org.jdesktop.layout.GroupLayout.TRAILING, generalPic1Label)) + .add(18, 18, 18) + .add(yourImagePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, localLabel2) + .add(org.jdesktop.layout.GroupLayout.TRAILING, generalPic2Label)) + .addContainerGap()) + ); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(yourImagePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(yourImagePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + ); + + pack(); + }// + + private void localPic1Clicked(java.awt.event.MouseEvent evt) { + + String title = "Sequoia Park"; + displayImage("/sequoiaPark.jpg", title, 0); + + } + + private void generalPic1Clicked(java.awt.event.MouseEvent evt) { + + String title = "Ostuni, Italy"; + displayImage("/Ostuni.jpg", title, 0); + + } + + private void generalPic2Clicked(java.awt.event.MouseEvent evt) { + + String title = "Argonauti, Italy"; + displayImage("/Argonauti.tif", title, 1); + + } + + private void localLabel2Clicked(java.awt.event.MouseEvent evt) { + + String title = "Koln Cathedral"; + displayImage("/KolnCathedral.tif", title, 1); + + } + + private void displayImage(String im, String t, int type) { + + if (type == 0) { + java.net.URL url; + url = getClass().getResource(im); + java.awt.Image image = Toolkit.getDefaultToolkit().getImage(url); + imp = new ImagePlus(t, image); + if (imp != null) { + imp.show(); + moveWindow(imp, 400, 0); + } + } else { + InputStream is = getClass().getResourceAsStream(im); + if (is != null) { + Opener opener = new Opener(); + imp = opener.openTiff(is, t); + if (imp != null) { + imp.show(); + moveWindow(imp, 400, 0); + } + } + } + + PickSubject ps = new PickSubject(); + AAPC_Var.putPickSubject(ps); + + AAPC_Var.hideYourImage(); + AAPC_Var.showPicSubject(); + + AAPC_Var.putImage(imp); + + } + + private void moveWindow(ImagePlus impl, int x, int y) { + + impl.getWindow().setLocation(x, y); + + } + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(YourImage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(YourImage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(YourImage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(YourImage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(new Runnable() { + @Override + public void run() { + new YourImage().setVisible(true); + } + }); + } + // Variables declaration - do not modify + private javax.swing.JLabel chooseBackgroundLabel; + private javax.swing.JLabel generalLabel; + private javax.swing.JLabel generalPic1Label; + private javax.swing.JLabel generalPic2Label; + private javax.swing.JLabel localLabel; + private javax.swing.JLabel localLabel2; + private javax.swing.JLabel localPic1Label; + private javax.swing.JPanel yourImagePanel; + // End of variables declaration + // global variables + ImagePlus imp, img; +} \ No newline at end of file diff --git a/src/main/resources/Argonauti.jpg b/src/main/resources/Argonauti.jpg new file mode 100644 index 0000000..0c9011f Binary files /dev/null and b/src/main/resources/Argonauti.jpg differ diff --git a/src/main/resources/Argonauti.tif b/src/main/resources/Argonauti.tif new file mode 100644 index 0000000..10b64fe Binary files /dev/null and b/src/main/resources/Argonauti.tif differ diff --git a/src/main/resources/English.jpg b/src/main/resources/English.jpg new file mode 100644 index 0000000..2031e1f Binary files /dev/null and b/src/main/resources/English.jpg differ diff --git a/src/main/resources/FontColorBlack.jpg b/src/main/resources/FontColorBlack.jpg new file mode 100644 index 0000000..f722b27 Binary files /dev/null and b/src/main/resources/FontColorBlack.jpg differ diff --git a/src/main/resources/FontColorBlue.jpg b/src/main/resources/FontColorBlue.jpg new file mode 100644 index 0000000..c41d508 Binary files /dev/null and b/src/main/resources/FontColorBlue.jpg differ diff --git a/src/main/resources/FontColorBrown.jpg b/src/main/resources/FontColorBrown.jpg new file mode 100644 index 0000000..1c1612f Binary files /dev/null and b/src/main/resources/FontColorBrown.jpg differ diff --git a/src/main/resources/FontColorCyan.jpg b/src/main/resources/FontColorCyan.jpg new file mode 100644 index 0000000..821d795 Binary files /dev/null and b/src/main/resources/FontColorCyan.jpg differ diff --git a/src/main/resources/FontColorGreen.jpg b/src/main/resources/FontColorGreen.jpg new file mode 100644 index 0000000..a6e71cd Binary files /dev/null and b/src/main/resources/FontColorGreen.jpg differ diff --git a/src/main/resources/FontColorMagenta.jpg b/src/main/resources/FontColorMagenta.jpg new file mode 100644 index 0000000..b44a344 Binary files /dev/null and b/src/main/resources/FontColorMagenta.jpg differ diff --git a/src/main/resources/FontColorOrange.jpg b/src/main/resources/FontColorOrange.jpg new file mode 100644 index 0000000..4659955 Binary files /dev/null and b/src/main/resources/FontColorOrange.jpg differ diff --git a/src/main/resources/FontColorPurple.jpg b/src/main/resources/FontColorPurple.jpg new file mode 100644 index 0000000..bea8a58 Binary files /dev/null and b/src/main/resources/FontColorPurple.jpg differ diff --git a/src/main/resources/FontColorRed.jpg b/src/main/resources/FontColorRed.jpg new file mode 100644 index 0000000..fc8ec09 Binary files /dev/null and b/src/main/resources/FontColorRed.jpg differ diff --git a/src/main/resources/FontColorWhite.jpg b/src/main/resources/FontColorWhite.jpg new file mode 100644 index 0000000..3159798 Binary files /dev/null and b/src/main/resources/FontColorWhite.jpg differ diff --git a/src/main/resources/FontColorYellow.jpg b/src/main/resources/FontColorYellow.jpg new file mode 100644 index 0000000..3b5430a Binary files /dev/null and b/src/main/resources/FontColorYellow.jpg differ diff --git a/src/main/resources/FontTemplate.jpg b/src/main/resources/FontTemplate.jpg new file mode 100644 index 0000000..b811847 Binary files /dev/null and b/src/main/resources/FontTemplate.jpg differ diff --git a/src/main/resources/France.jpg b/src/main/resources/France.jpg new file mode 100644 index 0000000..659433b Binary files /dev/null and b/src/main/resources/France.jpg differ diff --git a/src/main/resources/German.jpg b/src/main/resources/German.jpg new file mode 100644 index 0000000..22c631e Binary files /dev/null and b/src/main/resources/German.jpg differ diff --git a/src/main/resources/Italy.jpg b/src/main/resources/Italy.jpg new file mode 100644 index 0000000..40cf2c7 Binary files /dev/null and b/src/main/resources/Italy.jpg differ diff --git a/src/main/resources/KolnCathedral.tif b/src/main/resources/KolnCathedral.tif new file mode 100644 index 0000000..763d2da Binary files /dev/null and b/src/main/resources/KolnCathedral.tif differ diff --git a/src/main/resources/Ostuni.jpg b/src/main/resources/Ostuni.jpg new file mode 100644 index 0000000..6467fc4 Binary files /dev/null and b/src/main/resources/Ostuni.jpg differ diff --git a/src/main/resources/PrintingPostcard.exe b/src/main/resources/PrintingPostcard.exe new file mode 100755 index 0000000..c8cdd57 Binary files /dev/null and b/src/main/resources/PrintingPostcard.exe differ diff --git a/src/main/resources/S 1.jpg b/src/main/resources/S 1.jpg new file mode 100644 index 0000000..1f0ba6d Binary files /dev/null and b/src/main/resources/S 1.jpg differ diff --git a/src/main/resources/S 2.jpg b/src/main/resources/S 2.jpg new file mode 100644 index 0000000..ee2aad6 Binary files /dev/null and b/src/main/resources/S 2.jpg differ diff --git a/src/main/resources/Test.tif b/src/main/resources/Test.tif new file mode 100644 index 0000000..3f716f8 Binary files /dev/null and b/src/main/resources/Test.tif differ diff --git a/src/main/resources/fontcolor10.jpg b/src/main/resources/fontcolor10.jpg new file mode 100644 index 0000000..460d63f Binary files /dev/null and b/src/main/resources/fontcolor10.jpg differ diff --git a/src/main/resources/fontcolor11.jpg b/src/main/resources/fontcolor11.jpg new file mode 100644 index 0000000..4e4a743 Binary files /dev/null and b/src/main/resources/fontcolor11.jpg differ diff --git a/src/main/resources/fontcolor12.jpg b/src/main/resources/fontcolor12.jpg new file mode 100644 index 0000000..55d9e70 Binary files /dev/null and b/src/main/resources/fontcolor12.jpg differ diff --git a/src/main/resources/fontcolor13.jpg b/src/main/resources/fontcolor13.jpg new file mode 100644 index 0000000..a3bd7b2 Binary files /dev/null and b/src/main/resources/fontcolor13.jpg differ diff --git a/src/main/resources/fontcolor14.jpg b/src/main/resources/fontcolor14.jpg new file mode 100644 index 0000000..3ba5692 Binary files /dev/null and b/src/main/resources/fontcolor14.jpg differ diff --git a/src/main/resources/fontcolor15.jpg b/src/main/resources/fontcolor15.jpg new file mode 100644 index 0000000..5f94aff Binary files /dev/null and b/src/main/resources/fontcolor15.jpg differ diff --git a/src/main/resources/fontcolor3.jpg b/src/main/resources/fontcolor3.jpg new file mode 100644 index 0000000..0a83ed5 Binary files /dev/null and b/src/main/resources/fontcolor3.jpg differ diff --git a/src/main/resources/fontcolor4.jpg b/src/main/resources/fontcolor4.jpg new file mode 100644 index 0000000..aa78a47 Binary files /dev/null and b/src/main/resources/fontcolor4.jpg differ diff --git a/src/main/resources/fontcolor5.jpg b/src/main/resources/fontcolor5.jpg new file mode 100644 index 0000000..10b4230 Binary files /dev/null and b/src/main/resources/fontcolor5.jpg differ diff --git a/src/main/resources/fontcolor6.jpg b/src/main/resources/fontcolor6.jpg new file mode 100644 index 0000000..5e2219c Binary files /dev/null and b/src/main/resources/fontcolor6.jpg differ diff --git a/src/main/resources/fontcolor7.jpg b/src/main/resources/fontcolor7.jpg new file mode 100644 index 0000000..2ff4996 Binary files /dev/null and b/src/main/resources/fontcolor7.jpg differ diff --git a/src/main/resources/fontcolor8.jpg b/src/main/resources/fontcolor8.jpg new file mode 100644 index 0000000..8ae965f Binary files /dev/null and b/src/main/resources/fontcolor8.jpg differ diff --git a/src/main/resources/fontcolor9.jpg b/src/main/resources/fontcolor9.jpg new file mode 100644 index 0000000..d48717a Binary files /dev/null and b/src/main/resources/fontcolor9.jpg differ diff --git a/src/main/resources/horiz1.jpg b/src/main/resources/horiz1.jpg new file mode 100644 index 0000000..153496f Binary files /dev/null and b/src/main/resources/horiz1.jpg differ diff --git a/src/main/resources/icon_Argonauti.jpg b/src/main/resources/icon_Argonauti.jpg new file mode 100644 index 0000000..913800e Binary files /dev/null and b/src/main/resources/icon_Argonauti.jpg differ diff --git a/src/main/resources/icon_KolnCathedral.jpg b/src/main/resources/icon_KolnCathedral.jpg new file mode 100644 index 0000000..46bcd93 Binary files /dev/null and b/src/main/resources/icon_KolnCathedral.jpg differ diff --git a/src/main/resources/icon_Ostuni.jpg b/src/main/resources/icon_Ostuni.jpg new file mode 100644 index 0000000..63a01ef Binary files /dev/null and b/src/main/resources/icon_Ostuni.jpg differ diff --git a/src/main/resources/icon_sequoia.jpg b/src/main/resources/icon_sequoia.jpg new file mode 100644 index 0000000..c483d33 Binary files /dev/null and b/src/main/resources/icon_sequoia.jpg differ diff --git a/src/main/resources/pcH1.jpg b/src/main/resources/pcH1.jpg new file mode 100644 index 0000000..33e9738 Binary files /dev/null and b/src/main/resources/pcH1.jpg differ diff --git a/src/main/resources/pcH2.jpg b/src/main/resources/pcH2.jpg new file mode 100644 index 0000000..bcba598 Binary files /dev/null and b/src/main/resources/pcH2.jpg differ diff --git a/src/main/resources/pcH4.jpg b/src/main/resources/pcH4.jpg new file mode 100644 index 0000000..823e97b Binary files /dev/null and b/src/main/resources/pcH4.jpg differ diff --git a/src/main/resources/pcV1.jpg b/src/main/resources/pcV1.jpg new file mode 100644 index 0000000..7c9fdbb Binary files /dev/null and b/src/main/resources/pcV1.jpg differ diff --git a/src/main/resources/pcV1H2.jpg b/src/main/resources/pcV1H2.jpg new file mode 100644 index 0000000..fc1dc0e Binary files /dev/null and b/src/main/resources/pcV1H2.jpg differ diff --git a/src/main/resources/pcV2.jpg b/src/main/resources/pcV2.jpg new file mode 100644 index 0000000..eed39a4 Binary files /dev/null and b/src/main/resources/pcV2.jpg differ diff --git a/src/main/resources/pcV2H1.jpg b/src/main/resources/pcV2H1.jpg new file mode 100644 index 0000000..6d31e09 Binary files /dev/null and b/src/main/resources/pcV2H1.jpg differ diff --git a/src/main/resources/pcV4.jpg b/src/main/resources/pcV4.jpg new file mode 100644 index 0000000..761e596 Binary files /dev/null and b/src/main/resources/pcV4.jpg differ diff --git a/src/main/resources/pic1.jpg b/src/main/resources/pic1.jpg new file mode 100644 index 0000000..9aba14e Binary files /dev/null and b/src/main/resources/pic1.jpg differ diff --git a/src/main/resources/pic1canada.jpg b/src/main/resources/pic1canada.jpg new file mode 100644 index 0000000..a5dbacb Binary files /dev/null and b/src/main/resources/pic1canada.jpg differ diff --git a/src/main/resources/pic1surf.jpg b/src/main/resources/pic1surf.jpg new file mode 100644 index 0000000..933e555 Binary files /dev/null and b/src/main/resources/pic1surf.jpg differ diff --git a/src/main/resources/pic2.jpg b/src/main/resources/pic2.jpg new file mode 100644 index 0000000..8b70609 Binary files /dev/null and b/src/main/resources/pic2.jpg differ diff --git a/src/main/resources/pic2canada.jpg b/src/main/resources/pic2canada.jpg new file mode 100644 index 0000000..05003e4 Binary files /dev/null and b/src/main/resources/pic2canada.jpg differ diff --git a/src/main/resources/pic2koln.jpg b/src/main/resources/pic2koln.jpg new file mode 100644 index 0000000..9dcf728 Binary files /dev/null and b/src/main/resources/pic2koln.jpg differ diff --git a/src/main/resources/plugins.config b/src/main/resources/plugins.config new file mode 100644 index 0000000..e6585f7 --- /dev/null +++ b/src/main/resources/plugins.config @@ -0,0 +1,6 @@ +# Name: A_Postcard +# Author: The GAIA Group +# Version: 0.1.0 + + +File, "Postcard", A_Postcard diff --git a/src/main/resources/sequoiaPark.jpg b/src/main/resources/sequoiaPark.jpg new file mode 100644 index 0000000..7a6d226 Binary files /dev/null and b/src/main/resources/sequoiaPark.jpg differ diff --git a/src/main/resources/spanish.jpg b/src/main/resources/spanish.jpg new file mode 100644 index 0000000..7c1f7b7 Binary files /dev/null and b/src/main/resources/spanish.jpg differ diff --git a/src/main/resources/veer1.jpg b/src/main/resources/veer1.jpg new file mode 100644 index 0000000..9cc12dc Binary files /dev/null and b/src/main/resources/veer1.jpg differ