Skip to content
Snippets Groups Projects
Commit 5e6e8128 authored by Matej Kovár's avatar Matej Kovár
Browse files

added methods for loading primary face from file

parent 477e282c
No related branches found
No related tags found
No related merge requests found
......@@ -67,10 +67,10 @@
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="jPanel4" min="-2" pref="181" max="-2" attributes="0"/>
<Component id="jPanel4" min="-2" pref="180" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jPanel5" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="579" max="32767" attributes="0"/>
<EmptySpace pref="580" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
......@@ -88,7 +88,57 @@
</Property>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout"/>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
<Property name="useNullLayout" type="boolean" value="false"/>
</Layout>
<SubComponents>
<Container class="javax.swing.JPanel" name="jPanel2">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="57" green="57" red="0" type="rgb"/>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="30" y="30" width="120" height="120"/>
</Constraint>
</Constraints>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel1" pref="100" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel1" pref="98" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="18" style="0"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property>
<Property name="horizontalAlignment" type="int" value="0"/>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel5">
<Properties>
......@@ -113,6 +163,9 @@
<ResourceString bundle="cz/fidentis/analyst/gui/Bundle.properties" key="ProjectTopComp.addButton1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="addButton1MouseClicked"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="0" gridWidth="1" gridHeight="1" fill="0" ipadX="20" ipadY="0" insetsTop="16" insetsLeft="16" insetsBottom="13" insetsRight="4" anchor="13" weightX="0.0" weightY="0.0"/>
......
......@@ -11,6 +11,14 @@ import org.openide.awt.ActionReference;
import org.openide.windows.TopComponent;
import org.openide.util.NbBundle.Messages;
import cz.fidentis.analyst.Project;
import cz.fidentis.analyst.face.HumanFace;
import cz.fidentis.analyst.mesh.io.ModelFileFilter;
import java.awt.Dimension;
import java.io.File;
import java.io.IOException;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
/**
* The main panel enabling analysts to select the primary and secondary faces,
......@@ -65,6 +73,8 @@ public final class ProjectTopComp extends TopComponent {
jPanel1 = new javax.swing.JPanel();
jPanel4 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jPanel5 = new javax.swing.JPanel();
addButton1 = new javax.swing.JButton();
removeButton1 = new javax.swing.JButton();
......@@ -81,6 +91,32 @@ public final class ProjectTopComp extends TopComponent {
jPanel4.setBackground(new java.awt.Color(2, 138, 129));
jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jPanel4.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jPanel2.setBackground(new java.awt.Color(0, 87, 87));
jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
jLabel1.setForeground(new java.awt.Color(204, 204, 204));
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)
.addContainerGap())
);
jPanel4.add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 30, 120, 120));
jPanel5.setBackground(new java.awt.Color(2, 138, 129));
jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder());
......@@ -88,6 +124,11 @@ public final class ProjectTopComp extends TopComponent {
addButton1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(addButton1, org.openide.util.NbBundle.getMessage(ProjectTopComp.class, "ProjectTopComp.addButton1.text")); // NOI18N
addButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
addButton1MouseClicked(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
......@@ -163,22 +204,29 @@ public final class ProjectTopComp extends TopComponent {
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(579, Short.MAX_VALUE))
.addContainerGap(580, Short.MAX_VALUE))
);
add(jPanel1, java.awt.BorderLayout.CENTER);
}// </editor-fold>//GEN-END:initComponents
private void addButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addButton1MouseClicked
loadModel();
}//GEN-LAST:event_addButton1MouseClicked
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton addButton1;
private javax.swing.JButton analyzeButton1;
private javax.swing.JButton collapseButton1;
private javax.swing.JButton deselectAllButton1;
private javax.swing.JButton inflateButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JButton removeButton1;
......@@ -205,4 +253,56 @@ public final class ProjectTopComp extends TopComponent {
String version = p.getProperty("version");
// TODO read your settings according to their version
}
/**
* Loads model selected in file chooser by user
*/
public void loadModel () {
String[] extensions = new String[2];
extensions[0] = "obj";
extensions[1] = "OBJ";
//enables to shows just .obj files in file chooser
ModelFileFilter filter = new ModelFileFilter(extensions, "*.obj");
JFileChooser jFileChooser1 = new JFileChooser();
jFileChooser1.setPreferredSize(new Dimension (800,500));
jFileChooser1.addChoosableFileFilter(filter);
//file chooser will appear on top of projectTopComp
jFileChooser1.showOpenDialog(this);
jFileChooser1.setDialogTitle("Import obj file");
//setPrefferedModelPath(jFileChooser1.getCurrentDirectory().toString());
File[] fileArray = new File[1];
//saves selected file by user as first element in array
fileArray[0] = jFileChooser1.getSelectedFile();
if (fileArray.length <= 0) {
System.out.print("No file chosen.");
} else {
this.addModel(fileArray[0]);
}
}
/**
* Loads the model in .obj format from file and adds this model to project
* as primary face. If file is not correct, shows dialog with message.
*
* @param file File from which model will be read
*/
private void addModel (final File file) {
try {
HumanFace loadedFace;
loadedFace = new HumanFace(new File (file.getPath()));
this.project.setPrimaryFace(loadedFace);
jLabel1.setText("Loaded");
} catch (IOException e) {
System.out.println(e.getMessage());
JOptionPane.showMessageDialog(this, "File doesn't contain any model", "Model is not loaded.",
0, new ImageIcon(getClass().getResource("/notLoadedModel.png")));
System.out.println ("File doesn't contain any model");
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment