Skip to content

Commit

Permalink
And with this nifty-editor 0.5.9 is almost completed ! There's only s…
Browse files Browse the repository at this point in the history
…ome testing left and a more properties for the new elements . So this closes #7 and also gives some fixes to jFilechooser implementation
  • Loading branch information
relu91 committed Apr 18, 2014
1 parent 3b5dd7c commit 509e209
Show file tree
Hide file tree
Showing 10 changed files with 318 additions and 37 deletions.
Binary file added lib/beans-binding/beansbinding-1.2.1-doc.zip
Binary file not shown.
Binary file added lib/beans-binding/beansbinding-1.2.1.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions lib/nblibraries.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
libs.beans-binding.classpath=\
${base}/beans-binding/beansbinding-1.2.1.jar
libs.beans-binding.displayName=Beans Binding
libs.beans-binding.javadoc=\
${base}/beans-binding/beansbinding-1.2.1-doc.zip
libs.CopyLibs.classpath=\
${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar
libs.CopyLibs.displayName=CopyLibs Task
Expand Down
3 changes: 2 additions & 1 deletion nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ javac.classpath=\
${file.reference.relaxngDatatype-1.5.jar}:\
${file.reference.xsom-20110101-SNAPSHOT.jar}:\
${file.reference.nifty-default-controls-1.4.0-20131229.185046-101.jar}:\
${file.reference.nifty-1.4.0-SNAPSHOT.jar}
${file.reference.nifty-1.4.0-SNAPSHOT.jar}:\
${libs.beans-binding.classpath}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
Expand Down
21 changes: 19 additions & 2 deletions src/jada/ngeditor/guiviews/PropTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
*/
public class PropTable extends JTable{
private static final JComboEditor layoutEditor = new JComboEditor("absolute","center", "vertical", "horizontal","overlay");
private static final JComboEditor alingEditor = new JComboEditor("left","center", "right");
private static final JComboEditor valingEditor = new JComboEditor("top","center", "bottom");
private static final SizeEditor sizeEditor = new SizeEditor();
private static final String [] sizeValues = {"height","width","x","y"};
private GUIEditor editor;
public PropTable() {
super();
Expand Down Expand Up @@ -80,8 +84,12 @@ public TableCellEditor getCellEditor(int row, int column) {
}else if(pname.equalsIgnoreCase("filename")
|| pname.equalsIgnoreCase("backgroundImage")){
editor = new FileChooserEditor(this.editor.getGui().getAssetFolder());
}else if( pname.equalsIgnoreCase("height")){
editor = new SizeEditor();
}else if(isSizeValue(pname)){
editor = sizeEditor;
}else if( pname.equalsIgnoreCase("valign")){
editor = valingEditor;
}else if( pname.equalsIgnoreCase("align")){
editor = alingEditor;
}
return editor;
}
Expand All @@ -91,5 +99,14 @@ public TableCellEditor getCellEditor(int row, int column) {
public void setEditor(GUIEditor editor){
this.editor = editor;
}

private boolean isSizeValue(String pname) {
boolean res = false;
for(String s : sizeValues){
if(s.equals(pname))
res = true;
}
return res;
}

}
1 change: 1 addition & 0 deletions src/jada/ngeditor/guiviews/editors/FileChooserEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ private JPanel createAccessor(){
group.add(copy);
group.add(relative);
group.add(absolute);
absolute.setSelected(true);
result.add(new ImagePreview(jFileChooser1));
result.add(absolute);
result.add(relative);
Expand Down
143 changes: 110 additions & 33 deletions src/jada/ngeditor/guiviews/editors/SizeEditor.java
Original file line number Diff line number Diff line change
@@ -1,59 +1,136 @@
package jada.ngeditor.guiviews.editors;

import de.lessvoid.nifty.tools.SizeValue;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.AbstractCellEditor;
import javax.swing.ButtonGroup;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.TableCellEditor;

public class SizeEditor extends AbstractCellEditor implements TableCellEditor, Runnable {
private SizeEditorComponent editor = new SizeEditorComponent();
private JLabel label = new JLabel();

public class SizeEditor extends AbstractCellEditor implements TableCellEditor,ActionListener,PropertyChangeListener {
private JPanel editorPane;
private ButtonGroup group;
private JRadioButton perc;
private JRadioButton px;
private JRadioButton fill;
private ValueEditor percEditor = new ValueEditor();
private ValueEditor pxEditor = new ValueEditor();
private SizeValue edited = null;
public SizeEditor(){
GridBagLayout gridLayout = new GridBagLayout();
editorPane = new JPanel(gridLayout);
GridBagConstraints c = new GridBagConstraints();
perc = new JRadioButton("Percentage");
px = new JRadioButton("Pixel");
fill = new JRadioButton("*");
fill.setToolTipText("Wildcard, leave this value to layoutmanger");
fill.addActionListener(this);
px.addActionListener(this);
perc.addActionListener(this);
group = new ButtonGroup();
group.add(perc);
group.add(px);
group.add(fill);
px.setSelected(true);
c.gridx = 0;
c.anchor = GridBagConstraints.FIRST_LINE_START;
editorPane.add(perc,c);
c.gridx=1;
editorPane.add(percEditor,c);
c.gridx = 0;
c.gridy = 1;
editorPane.add(px,c);
c.gridx = 1;
c.gridy = 1;
editorPane.add(pxEditor,c);
c.gridx = 0;
c.gridy = 2;
editorPane.add(fill,c);
this.percEditor.setEnabled(false);
this.percEditor.setValue(SizeValue.percent(50));
this.pxEditor.setEnabled(true);
percEditor.addPropertyChangeListener(this);
pxEditor.addPropertyChangeListener(this);

}
@Override
public Object getCellEditorValue() {
return editor.getValueAsString();
return this.edited.toString();
}

@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
editor.showDialog(table, asInteger(value), 0, this);
label.setText(String.valueOf(value));
return label;
SizeValue val = new SizeValue(value.toString());
this.setUpByType(val);
SwingUtilities.invokeLater(new Runnable() {

@Override
public void run() {
int res = JOptionPane.showConfirmDialog(null, editorPane,"SizeEditor", JOptionPane.OK_CANCEL_OPTION);
if(res == JOptionPane.OK_OPTION){
fireEditingStopped();
}else{
cancelCellEditing();
}
}
});

return new JLabel(this.edited.toString());
}

private Integer asInteger(Object value) {
private void setUpByType(Object value) {
if(value == null) {
return 0;
this.px.setEnabled(true);
} else {
StringBuilder buff = new StringBuilder();
String s = value.toString();
for(int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if(Character.isDigit(c)) {
buff.append(c);
}
}
if(buff.length() == 0) {
buff.append(0);
}
int num = Integer.parseInt(buff.toString());
if(s.endsWith("px")) {
editor.radiobuttonpixel.setSelected(true);
editor.updateEditorState();
editor.spinnerpixel.setValue(num);
this.percEditor.setEnabled(false);
this.pxEditor.setEnabled(true);
this.pxEditor.setValue((SizeValue)value);
this.px.getModel().setSelected(true);
} else if(s.endsWith("%")) {
editor.radiobuttonpercent.setSelected(true);
editor.updateEditorState();
editor.spinnerpercent.setValue(num);
this.percEditor.setEnabled(true);
this.pxEditor.setEnabled(false);
this.percEditor.setValue((SizeValue)value);
this.perc.getModel().setSelected(true);
} else if(s.equals("*")) {
editor.radiobuttonfill.setSelected(true);
editor.updateEditorState();
}
return num;
this.percEditor.setEnabled(false);
this.pxEditor.setEnabled(false);
this.fill.getModel().setSelected(true);
this.edited = SizeValue.wildcard();
}
}
}

public void run() {
fireEditingStopped();
@Override
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if(fill.equals(source)){
this.setUpByType(new SizeValue("*"));
}else if(px.equals(source)){
this.setUpByType(new SizeValue("0px"));
}else if(perc.equals(source)){
this.setUpByType(new SizeValue("50%"));
}
}

@Override
public void propertyChange(PropertyChangeEvent evt) {
if(evt.getPropertyName().equals("value")){
this.edited = (SizeValue) evt.getNewValue();
}
}
}
52 changes: 52 additions & 0 deletions src/jada/ngeditor/guiviews/editors/ValueEditor.form
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8" ?>

<Form version="1.5" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,0,54,0,0,1,-125"/>
</AuxValues>

<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout">
<Property name="horizontalGap" type="int" value="10"/>
</Layout>
<SubComponents>
<Component class="javax.swing.JSlider" name="jSlider1">
<Properties>
<Property name="majorTickSpacing" type="int" value="50"/>
<Property name="minorTickSpacing" type="int" value="5"/>
<Property name="paintLabels" type="boolean" value="true"/>
<Property name="paintTicks" type="boolean" value="true"/>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[300, 45]"/>
</Property>
</Properties>
<BindingProperties>
<BindingProperty name="value" source="jSpinner1" sourcePath="${value}" target="jSlider1" targetPath="value" updateStrategy="0" immediately="false">
<BindingParameter name="IGNORE_ADJUSTING" value="N"/>
<Property name="name" type="java.lang.String" value=""/>
</BindingProperty>
</BindingProperties>
</Component>
<Component class="javax.swing.JSpinner" name="jSpinner1">
<Properties>
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Integer" stepSize="1" type="number"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[51, 20]"/>
</Property>
</Properties>
<BindingProperties>
<BindingProperty name="value" source="jSlider1" sourcePath="${value}" target="jSpinner1" targetPath="value" updateStrategy="0" immediately="false"/>
</BindingProperties>
</Component>
</SubComponents>
</Form>
Loading

0 comments on commit 509e209

Please sign in to comment.