Zoom In/Out feature

git-svn-id: https://svn.code.sf.net/p/jailer/code/trunk@1598 3dd849cd-670e-4645-a7cd-dd197c8d0e81
This commit is contained in:
rwisser
2018-03-29 06:32:22 +00:00
parent f8c06728cb
commit 6dfab43dcc
7 changed files with 117 additions and 19 deletions
+3
View File
@@ -1,3 +1,6 @@
7.6.6
- Minor GUI Improvements and bug fixes.
7.6.5
- Minor GUI Improvements and bug fixes.
@@ -25,7 +25,7 @@ public class JailerVersion {
/**
* The Jailer version.
*/
public static final String VERSION = "7.6.5";
public static final String VERSION = "7.6.6";
/**
* The Jailer working tables version.
@@ -561,7 +561,7 @@ public abstract class BrowserContentPane extends javax.swing.JPanel {
if (render instanceof JLabel) {
if (value != null && value.toString().trim().length() > 0) {
String tooltip = ConditionEditor.toMultiLine(value.toString());
((JLabel) render).setToolTipText(UIUtil.toHTML(tooltip, 500));
((JLabel) render).setToolTipText(UIUtil.toHTML(tooltip, 200));
} else {
((JLabel) render).setToolTipText(null);
}
@@ -590,7 +590,7 @@ public abstract class BrowserContentPane extends javax.swing.JPanel {
String value = f.getText();
if (value != null && value.toString().trim().length() > 0) {
String tooltip = ConditionEditor.toMultiLine(value.toString());
andCondition.setToolTipText(UIUtil.toHTML(tooltip, 500));
andCondition.setToolTipText(UIUtil.toHTML(tooltip, 200));
} else {
andCondition.setToolTipText(null);
}
@@ -827,7 +827,7 @@ public abstract class BrowserContentPane extends javax.swing.JPanel {
((JLabel) render).setFont(highlightedRows.contains(rowSorter.convertRowIndexToModel(row)) ? bold : nonbold);
String text = ((JLabel) render).getText();
if (text.indexOf('\n') >= 0) {
((JLabel) render).setToolTipText(UIUtil.toHTML(text, 400));
((JLabel) render).setToolTipText(UIUtil.toHTML(text, 200));
} else if (text.length() > 20) {
((JLabel) render).setToolTipText(text);
}
@@ -810,7 +810,7 @@ public abstract class SQLConsole extends javax.swing.JPanel {
private void updateOutline(String sql, int startPosition) {
final int MAX_CONTEXT_LENGTH = 100;
final int MAX_TOOLTIP_LENGTH = 200;
final int MAX_TOOLTIP_LENGTH = 100;
List<OutlineInfo> outlineInfos = new ArrayList<OutlineInfo>();
provider.findAliases(SQLCompletionProvider.removeCommentsAndLiterals(sql), null, outlineInfos);
adjustLevels(outlineInfos);
@@ -49,6 +49,7 @@ public class BasicFormatterImpl {
BEGIN_CLAUSES.add( "right" );
BEGIN_CLAUSES.add( "inner" );
BEGIN_CLAUSES.add( "outer" );
BEGIN_CLAUSES.add( "cross" );
BEGIN_CLAUSES.add( "group" );
BEGIN_CLAUSES.add( "order" );
@@ -16,6 +16,7 @@
package net.sf.jailer.ui.syntaxtextarea;
import java.awt.Dialog;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Image;
import java.awt.Window;
@@ -83,6 +84,9 @@ public class RSyntaxTextAreaWithSQLSyntaxStyle extends RSyntaxTextArea implement
public static KeyStroke KS_RUN_ALL = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.ALT_DOWN_MASK);
public static KeyStroke KS_FORMAT = KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.SHIFT_DOWN_MASK|InputEvent.CTRL_DOWN_MASK);
public static KeyStroke KS_SELECTTABLE = KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0);
public static KeyStroke KS_ZOOMIN = KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, InputEvent.CTRL_DOWN_MASK);
public static KeyStroke KS_ZOOMOUT = KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, InputEvent.CTRL_DOWN_MASK);
public static KeyStroke KS_ZOOMRESET = KeyStroke.getKeyStroke(KeyEvent.VK_0, InputEvent.CTRL_DOWN_MASK);
/**
* Actions.
@@ -92,6 +96,9 @@ public class RSyntaxTextAreaWithSQLSyntaxStyle extends RSyntaxTextArea implement
public final Action explain;
public final Action formatSQL;
private final Action selectTableAction;
private final Action zoomIn;
private final Action zoomOut;
private final Action zoomReset;
public RSyntaxTextAreaWithSQLSyntaxStyle(boolean withExecuteActions, boolean withSelectTableAction) {
this.withExecuteActions = withExecuteActions;
@@ -100,20 +107,53 @@ public class RSyntaxTextAreaWithSQLSyntaxStyle extends RSyntaxTextArea implement
// setTabsEmulated(true);
// load images
try {
String dir = "/net/sf/jailer/ui/resource";
icon = scaleToLineHeight(new ImageIcon(MetaDataPanel.class.getResource(dir + "/sqlconsole.png")));
iconBegin = scaleToLineHeight(new ImageIcon(MetaDataPanel.class.getResource(dir + "/sqlconsolebegin.png")));
iconBeginEnd = scaleToLineHeight(new ImageIcon(MetaDataPanel.class.getResource(dir + "/sqlconsolebeginend.png")));
iconEnd = scaleToLineHeight(new ImageIcon(MetaDataPanel.class.getResource(dir + "/sqlconsoleend.png")));
iconf = scaleToLineHeight(new ImageIcon(MetaDataPanel.class.getResource(dir + "/sqlconsolef.png")));
iconBeginf = scaleToLineHeight(new ImageIcon(MetaDataPanel.class.getResource(dir + "/sqlconsolebeginf.png")));
iconBeginEndf = scaleToLineHeight(new ImageIcon(MetaDataPanel.class.getResource(dir + "/sqlconsolebeginendf.png")));
iconEndf = scaleToLineHeight(new ImageIcon(MetaDataPanel.class.getResource(dir + "/sqlconsoleendf.png")));
} catch (Exception e) {
e.printStackTrace();
}
loadImages();
zoomIn = new AbstractAction("Zoom In") {
{
putValue(ACCELERATOR_KEY, KS_ZOOMIN);
InputMap im = getInputMap();
im.put(KS_ZOOMIN, this);
ActionMap am = getActionMap();
am.put(this, this);
}
@Override
public void actionPerformed(ActionEvent e) {
zoom(1.1);
}
};
zoomOut = new AbstractAction("Zoom Out") {
{
putValue(ACCELERATOR_KEY, KS_ZOOMOUT);
InputMap im = getInputMap();
im.put(KS_ZOOMOUT, this);
ActionMap am = getActionMap();
am.put(this, this);
}
@Override
public void actionPerformed(ActionEvent e) {
zoom(1 / 1.1);
}
};
zoomReset = new AbstractAction("Restore Default Zoom") {
{
putValue(ACCELERATOR_KEY, KS_ZOOMRESET);
InputMap im = getInputMap();
im.put(KS_ZOOMRESET, this);
ActionMap am = getActionMap();
am.put(this, this);
}
@Override
public void actionPerformed(ActionEvent e) {
zoom(0);
}
};
formatSQL = new AbstractAction("Format SQL") {
{
putValue(ACCELERATOR_KEY, KS_FORMAT);
@@ -220,6 +260,33 @@ public class RSyntaxTextAreaWithSQLSyntaxStyle extends RSyntaxTextArea implement
updateMenuItemState();
}
private Double initialFontSize = null;
private Double currentFontSize = null;
private void zoom(double factor) {
if (currentFontSize == null) {
currentFontSize = (double) getFont().getSize();
}
if (initialFontSize == null) {
initialFontSize = currentFontSize;
}
if (factor == 0.0) {
currentFontSize = initialFontSize;
} else {
currentFontSize = currentFontSize * factor;
if (currentFontSize.intValue() == getFont().getSize()) {
if (factor > 1) {
++currentFontSize;
} else {
--currentFontSize;
}
}
currentFontSize = Math.max(currentFontSize, 4);
currentFontSize = Math.min(currentFontSize, 4 * initialFontSize);
}
setFont(new Font(getFont().getName(), getFont().getStyle(), currentFontSize.intValue()));
}
private ImageIcon scaleToLineHeight(ImageIcon imageIcon) {
double s = getLineHeight() / (double) imageIcon.getIconHeight();
return new ImageIcon(imageIcon.getImage().getScaledInstance((int)(imageIcon.getIconWidth()), (int)(imageIcon.getIconHeight() * s + 0.5), Image.SCALE_SMOOTH));
@@ -286,6 +353,11 @@ public class RSyntaxTextAreaWithSQLSyntaxStyle extends RSyntaxTextArea implement
menu.add(new JSeparator(), 3);
}
menu.addSeparator();
menu.add(zoomIn);
menu.add(zoomOut);
menu.add(zoomReset);
return menu;
}
@@ -763,6 +835,7 @@ public class RSyntaxTextAreaWithSQLSyntaxStyle extends RSyntaxTextArea implement
if (allowRun && setLineHighlights) {
if (!pending.get()) {
removeAllLineHighlights();
loadImages();
setHighlightCurrentLine(true);
if (gutter != null) {
gutter.removeAllTrackingIcons();
@@ -879,6 +952,27 @@ public class RSyntaxTextAreaWithSQLSyntaxStyle extends RSyntaxTextArea implement
}
}
private Integer lastLineHeight;
private void loadImages() {
if (lastLineHeight == null || lastLineHeight != getLineHeight()) {
lastLineHeight = getLineHeight();
try {
String dir = "/net/sf/jailer/ui/resource";
icon = scaleToLineHeight(new ImageIcon(MetaDataPanel.class.getResource(dir + "/sqlconsole.png")));
iconBegin = scaleToLineHeight(new ImageIcon(MetaDataPanel.class.getResource(dir + "/sqlconsolebegin.png")));
iconBeginEnd = scaleToLineHeight(new ImageIcon(MetaDataPanel.class.getResource(dir + "/sqlconsolebeginend.png")));
iconEnd = scaleToLineHeight(new ImageIcon(MetaDataPanel.class.getResource(dir + "/sqlconsoleend.png")));
iconf = scaleToLineHeight(new ImageIcon(MetaDataPanel.class.getResource(dir + "/sqlconsolef.png")));
iconBeginf = scaleToLineHeight(new ImageIcon(MetaDataPanel.class.getResource(dir + "/sqlconsolebeginf.png")));
iconBeginEndf = scaleToLineHeight(new ImageIcon(MetaDataPanel.class.getResource(dir + "/sqlconsolebeginendf.png")));
iconEndf = scaleToLineHeight(new ImageIcon(MetaDataPanel.class.getResource(dir + "/sqlconsoleendf.png")));
} catch (Exception e) {
e.printStackTrace();
}
}
}
private ImageIcon icon;
private ImageIcon iconBegin;
private ImageIcon iconBeginEnd;
@@ -826,7 +826,7 @@ public abstract class SQLCompletionProvider<SOURCE, SCHEMA, TABLE> extends Defau
scopesWithContext.add("values");
Map<String, TABLE> aliases = new LinkedHashMap<String, TABLE>();
Pattern pattern = Pattern.compile("(?:\\bas\\b)|(" + reClauseKW + ")|(,|\\(|\\)|=|<|>|!|\\.|\\b(?:on|where|left|right|full|inner|outer|join|and|or|not|set)\\b)|(" + reIdentifier + ")", Pattern.DOTALL|Pattern.CASE_INSENSITIVE);
Pattern pattern = Pattern.compile("(?:\\bas\\b)|(?:[&][\\w]+\\s*\\.\\.)|(" + reClauseKW + ")|(,|\\(|\\)|=|<|>|!|\\.|\\b(?:on|where|left|right|full|inner|outer|cross|join|and|or|not|set)\\b)|(" + reIdentifier + ")", Pattern.DOTALL|Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(statement + ")");
boolean inFrom = false;
boolean inWith = false;