Skip to content
Snippets Groups Projects
Commit 46acfc41 authored by Richard Pajerský's avatar Richard Pajerský
Browse files

File chooser opens on preffered path

parent 3e3b84e4
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,8 @@ import java.awt.Color; ...@@ -12,6 +12,8 @@ import java.awt.Color;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.Dimension; import java.awt.Dimension;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
...@@ -151,10 +153,10 @@ public class Canvas extends javax.swing.JPanel { ...@@ -151,10 +153,10 @@ public class Canvas extends javax.swing.JPanel {
//enables to shows just .obj files in file chooser //enables to shows just .obj files in file chooser
ModelFileFilter filter = new ModelFileFilter(extensions, "*.obj"); ModelFileFilter filter = new ModelFileFilter(extensions, "*.obj");
JFileChooser jFileChooser1 = new JFileChooser(); JFileChooser jFileChooser1 = new JFileChooser(getPrefferedModelPath());
jFileChooser1.setPreferredSize(new Dimension (800,500)); jFileChooser1.setPreferredSize(new Dimension (800,500));
jFileChooser1.addChoosableFileFilter(filter); jFileChooser1.addChoosableFileFilter(filter);
//file chooser will appear on top of glCanvas //file chooser will appear on top of glCanvas
jFileChooser1.showOpenDialog(this); jFileChooser1.showOpenDialog(this);
...@@ -164,6 +166,10 @@ public class Canvas extends javax.swing.JPanel { ...@@ -164,6 +166,10 @@ public class Canvas extends javax.swing.JPanel {
//saves selected file by user as first element in array //saves selected file by user as first element in array
fileArray[0] = jFileChooser1.getSelectedFile(); fileArray[0] = jFileChooser1.getSelectedFile();
//testing getting path TODO
JOptionPane.showConfirmDialog(null,
fileArray[0].getAbsoluteFile(), "", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (fileArray.length <= 0) { if (fileArray.length <= 0) {
System.out.print("No file chosen."); System.out.print("No file chosen.");
} else { } else {
...@@ -171,6 +177,20 @@ public class Canvas extends javax.swing.JPanel { ...@@ -171,6 +177,20 @@ public class Canvas extends javax.swing.JPanel {
} }
glCanvas.setVisible(true); glCanvas.setVisible(true);
} }
private String getPrefferedModelPath() {
String data = "";
try {
File myObj = new File(/*propPath + */"preferences.fip");
try (Scanner myReader = new Scanner(myObj)) {
data = myReader.nextLine();
}
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
return data;
}
/** /**
* Loads the model in .obj format from file and adds this model to listener for displaying. * Loads the model in .obj format from file and adds this model to listener for displaying.
......
...@@ -31,6 +31,7 @@ public class Installer extends ModuleInstall { ...@@ -31,6 +31,7 @@ public class Installer extends ModuleInstall {
java.util.logging.Logger.getLogger(UserInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(UserInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} }
java.awt.EventQueue.invokeLater(() -> { java.awt.EventQueue.invokeLater(() -> {
//old JFrame, disabled
/*frameMain = new UserInterface(); /*frameMain = new UserInterface();
frameMain.setBackground(new Color(49,165,154)); frameMain.setBackground(new Color(49,165,154));
frameMain.pack(); frameMain.pack();
......
...@@ -39,10 +39,10 @@ ...@@ -39,10 +39,10 @@
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="jTextField1" min="-2" max="-2" attributes="0"/> <Component id="jFormattedTextField1" pref="288" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="jButton1" min="-2" max="-2" attributes="0"/> <Component id="jButton1" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="250" max="32767" attributes="0"/> <EmptySpace min="-2" pref="18" max="-2" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
...@@ -51,8 +51,8 @@ ...@@ -51,8 +51,8 @@
<Group type="102" alignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0"> <Group type="103" groupAlignment="3" attributes="0">
<Component id="jTextField1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jFormattedTextField1" alignment="3" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace pref="266" max="32767" attributes="0"/> <EmptySpace pref="266" max="32767" attributes="0"/>
</Group> </Group>
...@@ -60,17 +60,17 @@ ...@@ -60,17 +60,17 @@
</DimensionLayout> </DimensionLayout>
</Layout> </Layout>
<SubComponents> <SubComponents>
<Component class="javax.swing.JTextField" name="jTextField1"> <Component class="javax.swing.JButton" name="jButton1">
<Properties> <Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="cz/fidentis/analyst/gui/Bundle.properties" key="PreferencesTopComponent.jTextField1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/> <ResourceString bundle="cz/fidentis/analyst/gui/Bundle.properties" key="PreferencesTopComponent.jButton1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property> </Property>
</Properties> </Properties>
</Component> </Component>
<Component class="javax.swing.JButton" name="jButton1"> <Component class="javax.swing.JFormattedTextField" name="jFormattedTextField1">
<Properties> <Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="cz/fidentis/analyst/gui/Bundle.properties" key="PreferencesTopComponent.jButton1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/> <ResourceString bundle="cz/fidentis/analyst/gui/Bundle.properties" key="PreferencesTopComponent.jFormattedTextField1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property> </Property>
</Properties> </Properties>
</Component> </Component>
......
...@@ -10,9 +10,17 @@ import org.openide.awt.ActionID; ...@@ -10,9 +10,17 @@ import org.openide.awt.ActionID;
import org.openide.awt.ActionReference; import org.openide.awt.ActionReference;
import org.openide.windows.TopComponent; import org.openide.windows.TopComponent;
import org.openide.util.NbBundle.Messages; import org.openide.util.NbBundle.Messages;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
import javax.swing.JOptionPane;
/** /**
* Top component which displays something. *
* @author Richard Pajerský
*
* Window with basic Preferences
*/ */
@ConvertAsProperties( @ConvertAsProperties(
dtd = "-//cz.fidentis.analyst.gui//Preferences//EN", dtd = "-//cz.fidentis.analyst.gui//Preferences//EN",
...@@ -25,7 +33,7 @@ import org.openide.util.NbBundle.Messages; ...@@ -25,7 +33,7 @@ import org.openide.util.NbBundle.Messages;
) )
@TopComponent.Registration(mode = "properties", openAtStartup = false) @TopComponent.Registration(mode = "properties", openAtStartup = false)
@ActionID(category = "Window", id = "cz.fidentis.analyst.gui.PreferencesTopComponent") @ActionID(category = "Window", id = "cz.fidentis.analyst.gui.PreferencesTopComponent")
@ActionReference(path = "Menu/Window" /*, position = 333 */) @ActionReference(path = "Menu/Tools", position = 2600, separatorBefore = 2550 /*, position = 333 */)
@TopComponent.OpenActionRegistration( @TopComponent.OpenActionRegistration(
displayName = "#CTL_PreferencesAction", displayName = "#CTL_PreferencesAction",
preferredID = "PreferencesTopComponent" preferredID = "PreferencesTopComponent"
...@@ -42,7 +50,24 @@ public final class PreferencesTopComponent extends TopComponent { ...@@ -42,7 +50,24 @@ public final class PreferencesTopComponent extends TopComponent {
setName(Bundle.CTL_PreferencesTopComponent()); setName(Bundle.CTL_PreferencesTopComponent());
setToolTipText(Bundle.HINT_PreferencesTopComponent()); setToolTipText(Bundle.HINT_PreferencesTopComponent());
putClientProperty(TopComponent.PROP_KEEP_PREFERRED_SIZE_WHEN_SLIDED_IN, Boolean.TRUE); putClientProperty(TopComponent.PROP_KEEP_PREFERRED_SIZE_WHEN_SLIDED_IN, Boolean.TRUE);
createPreferencesFile();
}
private void createPreferencesFile() {
//testing preferences fodler
//String propPath = System.getProperty("user.home") + "/preferences";
try {
File myObj = new File(/*propPath + */"preferences.fip");
if (myObj.createNewFile()) {
JOptionPane.showConfirmDialog(null, "File created: " + myObj.getName());
} else {
JOptionPane.showConfirmDialog(null, "File already exists." + myObj.getName());
}
} catch (IOException e) {
JOptionPane.showConfirmDialog(null, "An error occurred.");
e.printStackTrace();
}
} }
/** /**
...@@ -53,42 +78,58 @@ public final class PreferencesTopComponent extends TopComponent { ...@@ -53,42 +78,58 @@ public final class PreferencesTopComponent extends TopComponent {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() { private void initComponents() {
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton(); jButton1 = new javax.swing.JButton();
jFormattedTextField1 = new javax.swing.JFormattedTextField();
jTextField1.setText(org.openide.util.NbBundle.getMessage(PreferencesTopComponent.class, "PreferencesTopComponent.jTextField1.text")); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getMessage(PreferencesTopComponent.class, "PreferencesTopComponent.jButton1.text")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getMessage(PreferencesTopComponent.class, "PreferencesTopComponent.jButton1.text")); // NOI18N
jFormattedTextField1.setText(org.openide.util.NbBundle.getMessage(PreferencesTopComponent.class, "PreferencesTopComponent.jFormattedTextField1.text")); // NOI18N
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout); this.setLayout(layout);
layout.setHorizontalGroup( layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addContainerGap() .addContainerGap()
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jFormattedTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 288, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1) .addComponent(jButton1)
.addContainerGap(250, Short.MAX_VALUE)) .addGap(18, 18, 18))
); );
layout.setVerticalGroup( layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addContainerGap() .addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton1)
.addComponent(jButton1)) .addComponent(jFormattedTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(266, Short.MAX_VALUE)) .addContainerGap(266, Short.MAX_VALUE))
); );
}// </editor-fold>//GEN-END:initComponents }// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1; private javax.swing.JButton jButton1;
private javax.swing.JTextField jTextField1; private javax.swing.JFormattedTextField jFormattedTextField1;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
private String getPrefferedModelPath(){
String data = "";
try {
File myObj = new File(/*propPath + */"preferences.fip");
try (Scanner myReader = new Scanner(myObj)) {
data = myReader.nextLine();
}
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
return data;
}
@Override @Override
public void componentOpened() { public void componentOpened() {
// TODO add custom code on component opening // TODO add custom code on component opening
jFormattedTextField1.setText(getPrefferedModelPath());
} }
@Override @Override
......
#Localized module labels. Defaults taken from POM (<name>, <description>, <groupId>) if unset.
#OpenIDE-Module-Name=
#OpenIDE-Module-Short-Description=
#OpenIDE-Module-Long-Description=
#OpenIDE-Module-Display-Category=
#Thu Oct 03 09:09:53 CEST 2019
PreferencesTopComponent.jTextField1.text=jTextField1
PreferencesTopComponent.jButton1.text=jButton1 PreferencesTopComponent.jButton1.text=jButton1
PreferencesTopComponent.jFormattedTextField1.text=jFormattedTextField1
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