use of easik.EasikSettings in project fql by CategoricalData.
the class ProgramSettingsUI method addColorOptions.
/**
* Adds settings to the general colour tab pane
*
* @param colors
*/
protected void addColorOptions(OptionTab colors) {
EasikSettings s = Easik.getInstance().getSettings();
for (ColorField f : colorFields()) {
String name = f.name, setting = f.key;
if (setting == null) {
// A title
colors.addOption(new Option.Title(name));
continue;
}
ColorEditButton c = new ColorEditButton(setting);
_colorButtons.add(c);
// If it's one of these, add a width slider:
if (setting.matches("^(?:manip_|edit_)?edge_.*|.*_border$|^(?:path_)?selection$")) {
float currentValue = s.getFloat(setting + "_width", 10.0f);
JSlider widthSlider = new JSlider(10, 40, (int) (10 * currentValue));
if (setting.matches(".*_border$")) {
// Borders need an integer
// width
widthSlider.setMinorTickSpacing(10);
widthSlider.setSnapToTicks(true);
widthSlider.setPaintTicks(true);
}
_widthSliders.put(setting, widthSlider);
Dimension d = widthSlider.getPreferredSize();
widthSlider.setPreferredSize(new Dimension(120, d.height));
final JLabel width = new JLabel((currentValue + "").replaceAll("\\.?0+$", "") + " pixel" + ((currentValue == 1.0) ? "" : "s"));
widthSlider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
JSlider s = (JSlider) e.getSource();
@SuppressWarnings("unused") JPanel p = (JPanel) s.getParent();
width.setText(((s.getValue() / 10.0) + "").replaceAll("\\.?0+$", "") + " pixel" + ((s.getValue() == 10.0) ? "" : "s"));
}
});
colors.addOption(new Option(name, c, widthSlider, width));
} else {
colors.addOption(new JLabel(name), c);
}
}
}
use of easik.EasikSettings in project fql by CategoricalData.
the class ProgramSettingsUI method addSQLOptions.
/**
* @param sql
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void addSQLOptions(OptionTab sql) {
EasikSettings s = Easik.getInstance().getSettings();
String[] drivers = DriverInfo.availableDatabaseDrivers();
_sqlDriver = new JComboBox(drivers);
_sqlDriver.setSelectedItem(s.getProperty("sql_driver", drivers[0]));
sql.addOption(new JLabel("Default SQL driver"), _sqlDriver);
_sqlPKid = new JRadioButton("Use \"id\"");
_sqlPKTable_id = new JRadioButton("Use \"<tablename>_id\"");
_sqlPKCustomButton = new JRadioButton("Use custom name:");
ButtonGroup pk = new ButtonGroup();
pk.add(_sqlPKid);
pk.add(_sqlPKTable_id);
pk.add(_sqlPKCustomButton);
String pkColumns = s.getProperty("sql_pk_columns", "<table>_id");
if (pkColumns.equals("id")) {
_sqlPKid.setSelected(true);
} else if (pkColumns.equals("<table>_id")) {
_sqlPKTable_id.setSelected(true);
} else {
_sqlPKCustomButton.setSelected(true);
}
_sqlPKCustom = JUtils.textField(pkColumns);
JPanel customPK = new JPanel();
customPK.setLayout(new BoxLayout(customPK, BoxLayout.X_AXIS));
customPK.add(_sqlPKCustomButton);
customPK.add(_sqlPKCustom);
_sqlPKid.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_sqlPKCustom.setText("id");
}
});
_sqlPKTable_id.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_sqlPKCustom.setText("<table>_id");
}
});
JPanel pkSettings = new JPanel();
pkSettings.setLayout(new BoxLayout(pkSettings, BoxLayout.Y_AXIS));
pkSettings.add(_sqlPKid);
pkSettings.add(_sqlPKTable_id);
pkSettings.add(customPK);
pkSettings.setAlignmentX(Component.LEFT_ALIGNMENT);
_sqlPKid.setAlignmentX(Component.LEFT_ALIGNMENT);
_sqlPKTable_id.setAlignmentX(Component.LEFT_ALIGNMENT);
customPK.setAlignmentX(Component.LEFT_ALIGNMENT);
sql.addOption(new JLabel("Primary key column names"), pkSettings);
_sqlFKTargetTable = new JRadioButton("Use \"<target name>\"");
_sqlFKTargetTable_id = new JRadioButton("Use \"<target name>_id\"");
_sqlFKEdges = new JRadioButton("Use edge labels");
_sqlFKTargetEdge = new JRadioButton("Use \"<target name>_<edge label>\"");
_sqlFKCustomButton = new JRadioButton("Use custom name:");
ButtonGroup fk = new ButtonGroup();
fk.add(_sqlFKTargetTable);
fk.add(_sqlFKTargetTable_id);
fk.add(_sqlFKEdges);
fk.add(_sqlFKTargetEdge);
fk.add(_sqlFKCustomButton);
String fkColumns = s.getProperty("sql_fk_columns", "<target>_<edge>");
if (fkColumns.equals("<edge>")) {
_sqlFKEdges.setSelected(true);
} else if (fkColumns.equals("<target>")) {
_sqlFKTargetTable.setSelected(true);
} else if (fkColumns.equals("<target>_id")) {
_sqlFKTargetTable_id.setSelected(true);
} else if (fkColumns.equals("<target>_<edge>")) {
_sqlFKTargetEdge.setSelected(true);
} else {
_sqlFKCustomButton.setSelected(true);
}
_sqlFKCustom = JUtils.textField(fkColumns);
JPanel customFK = new JPanel();
customFK.setLayout(new BoxLayout(customFK, BoxLayout.X_AXIS));
customFK.add(_sqlFKCustomButton);
customFK.add(_sqlFKCustom);
_sqlFKEdges.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_sqlFKCustom.setText("<edge>");
}
});
_sqlFKTargetTable.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_sqlFKCustom.setText("<target>");
}
});
_sqlFKTargetTable_id.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_sqlFKCustom.setText("<target>_id");
}
});
_sqlFKTargetEdge.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_sqlFKCustom.setText("<target>_<edge>");
}
});
JPanel fkSettings = new JPanel();
fkSettings.setLayout(new BoxLayout(fkSettings, BoxLayout.Y_AXIS));
fkSettings.add(_sqlFKTargetTable);
fkSettings.add(_sqlFKTargetTable_id);
fkSettings.add(_sqlFKEdges);
fkSettings.add(_sqlFKTargetEdge);
fkSettings.add(customFK);
fkSettings.setAlignmentX(Component.LEFT_ALIGNMENT);
_sqlFKTargetTable.setAlignmentX(Component.LEFT_ALIGNMENT);
_sqlFKTargetTable_id.setAlignmentX(Component.LEFT_ALIGNMENT);
_sqlFKEdges.setAlignmentX(Component.LEFT_ALIGNMENT);
_sqlFKTargetEdge.setAlignmentX(Component.LEFT_ALIGNMENT);
customFK.setAlignmentX(Component.LEFT_ALIGNMENT);
sql.addOption(new JLabel("Foreign key column names"), fkSettings);
_sqlQuoting = new JCheckBox("Quote SQL identifiers");
_sqlQuoting.setSelected(s.getProperty("sql_quoting", "false").equals("true"));
JLabel quoteLabel = new JLabel("Identifier quoting");
String quoteTT = JUtils.tooltip("This option makes EASIK quote identifiers, which allows various non-alphanumeric characters (such as spaces and punctuation) in table and column names.\n\nNote also that quoted identifiers are, for many databases, case-sensitive.");
quoteLabel.setToolTipText(quoteTT);
_sqlQuoting.setToolTipText(quoteTT);
sql.addOption(quoteLabel, _sqlQuoting);
_sqlCascading = new JComboBox(new String[] { "Restrict deletions", "Cascade deletions" });
_sqlCascading.setSelectedIndex(s.getProperty("sql_cascade", "restrict").equals("cascade") ? 1 : 0);
_sqlCascadingPartial = new JComboBox(new String[] { "Set null", "Restrict deletions", "Cascade deletions" });
String partialCascading = s.getProperty("sql_cascade_partial", "set_null");
_sqlCascadingPartial.setSelectedIndex(partialCascading.equals("cascade") ? 2 : partialCascading.equals("restrict") ? 1 : 0);
JLabel cascadeLabel = new JLabel("Edge cascading");
String cascadeTT = JUtils.tooltip("This option affects how EASIK creates edges when exporting to a db.\n\n\"Cascade deletions\" cause deletions in one table to trigger deletions of any rows in other tables that point to the row(s) being deleted.\n\n\"Restrict deletions\" causes attempted deletions of referenced rows to fail.\n\nThis option will be used by default for normal and injective edges of new sketches. To change the default for new edges of an existing sketch, change the setting in the sketch's Document Information menu.");
cascadeLabel.setToolTipText(cascadeTT);
_sqlCascading.setToolTipText(cascadeTT);
sql.addOption(cascadeLabel, _sqlCascading);
JLabel cascadePartialLabel = new JLabel("Partial edge cascading");
String cascadePartialTT = JUtils.tooltip("This option affects how EASIK creates partial edges when exporting to a db.\n\n\"Cascade deletions\" cause deletions in one table to trigger deletions of any rows in other tables that point to the row(s) being deleted.\n\n\"Restrict deletions\" cause attempted deletions of referenced rows to fail.\n\n\"Set null\" causes references to be set to NULL when the targeted row is deleted.\n\nThis option will be used by default for partial edges of new sketches. To change the default for new edges of an existing sketch, change the setting in the sketch's Document Information menu.");
cascadePartialLabel.setToolTipText(cascadePartialTT);
_sqlCascadingPartial.setToolTipText(cascadePartialTT);
sql.addOption(cascadePartialLabel, _sqlCascadingPartial);
}
use of easik.EasikSettings in project fql by CategoricalData.
the class FileChooser method chooseFileAWT.
/*
* AWT FileDialog implementation of the file chooser. This is because
* JFileChooser doesn't work very well on non-Windows, but FileDialog
* doesn't work on Windows (it doesn't support file filters on Windows).
*/
/**
* @param title
* @param mode
* @param filter
*
* @return
*/
private static File chooseFileAWT(String title, Mode mode, FileFilter filter) {
Easik e = Easik.getInstance();
EasikSettings s = e.getSettings();
FileDialog dialog = new FileDialog(e.getFrame(), title, (mode == Mode.SAVE) ? FileDialog.SAVE : FileDialog.LOAD);
dialog.setDirectory(s.getDefaultFolder());
if ((mode == Mode.DIRECTORY) && EasikConstants.RUNNING_ON_MAC) {
System.setProperty("apple.awt.fileDialogForDirectories", "true");
} else if (filter != null) {
dialog.setFilenameFilter(filter);
}
// Show the dialog (this blocks until the user is done)
dialog.setVisible(true);
if ((mode == Mode.DIRECTORY) && EasikConstants.RUNNING_ON_MAC) {
System.setProperty("apple.awt.fileDialogForDirectories", "false");
}
String filename = dialog.getFile();
if (filename == null) {
return null;
}
File selected = new File(dialog.getDirectory(), filename);
if (mode != Mode.DIRECTORY) {
s.setProperty("folder_last", selected.getParentFile().getAbsolutePath());
}
return selected;
}
use of easik.EasikSettings in project fql by CategoricalData.
the class ModelVertexRenderer method installAttributes.
/**
* Takes the graph constants assigned and uses them with this class
*
* @param v
* @param attributes
* The attributes in use
*/
protected void installAttributes(ModelVertex<F, GM, M, N, E> v, Map<?, ?> attributes) {
_entityLabel.setIcon(GraphConstants.getIcon(attributes));
_entityLabel.setVerticalAlignment(GraphConstants.getVerticalAlignment(attributes));
_entityLabel.setHorizontalAlignment(GraphConstants.getHorizontalAlignment(attributes));
_entityLabel.setVerticalTextPosition(GraphConstants.getVerticalTextPosition(attributes));
_entityLabel.setHorizontalTextPosition(GraphConstants.getHorizontalTextPosition(attributes));
_entity.setOpaque(true);
_entityLabel.setOpaque(true);
String modeTag = (model.getFrame().getMode() == Mode.EDIT) ? "edit_" : "manip_";
setOpaque(GraphConstants.isOpaque(attributes));
setBorder(GraphConstants.getBorder(attributes));
Color bordercolor = GraphConstants.getBorderColor(attributes);
int borderWidth = Math.max(1, Math.round(GraphConstants.getLineWidth(attributes)));
if ((getBorder() == null) && (bordercolor != null)) {
setBorder(BorderFactory.createLineBorder(bordercolor, borderWidth));
}
if (bordercolor == null) {
if (getBorder() instanceof LineBorder) {
bordercolor = ((LineBorder) getBorder()).getLineColor();
} else {
bordercolor = Color.black;
}
}
Color foreground = GraphConstants.getForeground(attributes);
if (foreground == null) {
foreground = model.getForeground();
}
setForeground(foreground);
_entityLabel.setForeground(foreground);
Color background = GraphConstants.getBackground(attributes);
setBackground((background != null) ? background : model.getBackground());
EasikSettings s = Easik.getInstance().getSettings();
if (v != null) {
// TODO aql easik
_attributes.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, bordercolor));
_uniqueKeys.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, bordercolor));
Color entityFG = s.getColor(modeTag + "entity_fg", Color.black), entityBG = s.getColor(modeTag + "entity_bg", Color.white), attribFG = s.getColor(modeTag + "attribute_fg", foreground), attribBG = s.getColor(modeTag + "attribute_bg", background);
_entityLabel.setBackground(entityBG);
_entityLabel.setForeground(entityFG);
_attributes.setBackground(attribBG);
_attributes.setOpaque(true);
_uniqueKeys.setBackground(attribBG);
_uniqueKeys.setOpaque(true);
for (Component c : _attributes.getComponents()) {
c.setForeground(attribFG);
if (c instanceof JComponent) {
((JComponent) c).setOpaque(false);
}
}
for (Component c : _uniqueKeys.getComponents()) {
c.setForeground(attribFG);
if (c instanceof JComponent) {
((JComponent) c).setOpaque(false);
}
}
} else {
// A constraint
Color constFG = s.getColor(modeTag + "constraint_fg", Color.black), constBG = s.getColor(modeTag + "constraint_bg", Color.white);
_entityLabel.setBackground(constBG);
_entityLabel.setForeground(constFG);
}
gradientColor = GraphConstants.getGradientColor(attributes);
setFont(GraphConstants.getFont(attributes));
}
use of easik.EasikSettings in project fql by CategoricalData.
the class ProgramSettingsUI method accepted.
/**
* @param accepted
*/
@Override
public void accepted(boolean accepted) {
if (!accepted) {
return;
}
// The user hit OK, so save the various settings
EasikSettings s = Easik.getInstance().getSettings();
s.setProperty("attrib_display", _showAttsAndUniqueKeys.isSelected() ? "show" : "hide");
// s.setProperty("warning_display", _showWarnings.isSelected()
// ? "show"
// : "hide");
s.setProperty("folder_specified", _folderSpecificLoc.getText());
s.setProperty("folder_default", _folderSpecific.isSelected() ? "specified" : _folderRunning.isSelected() ? "pwd" : "last");
s.setProperty("thumb_scale_factor", (thumbScaleSlider.getValue() / 100.0) + "");
for (ColorEditButton c : _colorButtons) {
c.saveColor();
}
for (String setting : _widthSliders.keySet()) {
JSlider slider = _widthSliders.get(setting);
s.setProperty(setting + "_width", (slider.getValue() / 10.0) + "");
}
s.setProperty("sql_driver", "" + _sqlDriver.getSelectedItem());
s.setProperty("sql_pk_columns", _sqlPKid.isSelected() ? "id" : _sqlPKTable_id.isSelected() ? "<table>_id" : _sqlPKCustom.getText());
// _sqlFKTargetTable_id.isSelected()
s.setProperty(// _sqlFKTargetTable_id.isSelected()
"sql_fk_columns", // _sqlFKTargetTable_id.isSelected()
_sqlFKEdges.isSelected() ? "<edge>" : _sqlFKTargetEdge.isSelected() ? "<target>_<edge>" : _sqlFKTargetTable.isSelected() ? "<target>" : "<target>_id");
s.setProperty("sql_quoting", _sqlQuoting.isSelected() ? "true" : "false");
s.setProperty("sql_cascade", (_sqlCascading.getSelectedIndex() == 0) ? "restrict" : "cascade");
int parIndex = _sqlCascadingPartial.getSelectedIndex();
s.setProperty("sql_cascade_partial", (parIndex == 0) ? "set_null" : (parIndex == 1) ? "restrict" : "cascade");
Easik.getInstance().getFrame().getOverview().refreshAll();
}
Aggregations