-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
And with this nifty-editor 0.5.9 is almost completed ! There's only s…
…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
Showing
10 changed files
with
318 additions
and
37 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.