hzzz 8 years ago
parent
commit
411da370e4
  1. 14
      designer_base/src/com/fr/design/gui/autocomplete/AutoCompletePopupWindow.java
  2. 6
      designer_base/src/com/fr/design/gui/autocomplete/AutoCompletion.java
  3. 55
      designer_base/src/com/fr/design/gui/autocomplete/ParameterizedCompletionContext.java
  4. 15
      designer_base/src/com/fr/design/gui/itabpane/UITabsHeaderIconPane.java

14
designer_base/src/com/fr/design/gui/autocomplete/AutoCompletePopupWindow.java

@ -10,6 +10,7 @@
package com.fr.design.gui.autocomplete; package com.fr.design.gui.autocomplete;
import com.fr.design.gui.syntax.ui.rsyntaxtextarea.PopupWindowDecorator; import com.fr.design.gui.syntax.ui.rsyntaxtextarea.PopupWindowDecorator;
import com.fr.general.FRLogger;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.CaretEvent; import javax.swing.event.CaretEvent;
@ -301,7 +302,7 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener,
private void installKeyBindings() { private void installKeyBindings() {
if (AutoCompletion.isDebug()) { if (AutoCompletion.isDebug()) {
System.out.println("PopupWindow: Installing keybindings"); FRLogger.getLogger().debug("PopupWindow: Installing keybindings");
} }
if (escapeKap == null) { // Lazily create actions. if (escapeKap == null) { // Lazily create actions.
@ -386,15 +387,16 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener,
// Try to position to the right first (LTR) // Try to position to the right first (LTR)
int x; int x;
int dis = 5;
if (ac.getTextComponentOrientation().isLeftToRight()) { if (ac.getTextComponentOrientation().isLeftToRight()) {
x = getX() + getWidth() + 5; x = getX() + getWidth() + dis;
if (x + descWindow.getWidth() > screenBounds.x + screenBounds.width) { // doesn't fit if (x + descWindow.getWidth() > screenBounds.x + screenBounds.width) { // doesn't fit
x = getX() - 5 - descWindow.getWidth(); x = getX() - dis - descWindow.getWidth();
} }
} else { // RTL } else { // RTL
x = getX() - 5 - descWindow.getWidth(); x = getX() - dis - descWindow.getWidth();
if (x < screenBounds.x) { // Doesn't fit if (x < screenBounds.x) { // Doesn't fit
x = getX() + getWidth() + 5; x = getX() + getWidth() + dis;
} }
} }
@ -709,7 +711,7 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener,
private void uninstallKeyBindings() { private void uninstallKeyBindings() {
if (AutoCompletion.isDebug()) { if (AutoCompletion.isDebug()) {
System.out.println("PopupWindow: Removing keybindings"); FRLogger.getLogger().debug("PopupWindow: Removing keybindings");
} }
JTextComponent comp = ac.getTextComponent(); JTextComponent comp = ac.getTextComponent();

6
designer_base/src/com/fr/design/gui/autocomplete/AutoCompletion.java

@ -277,7 +277,7 @@ public class AutoCompletion {
* @return Whether to auto-complete single choices. * @return Whether to auto-complete single choices.
* @see #setAutoCompleteSingleChoices(boolean) * @see #setAutoCompleteSingleChoices(boolean)
*/ */
public boolean getAutoCompleteSingleChoices() { public boolean isAutoCompleteSingleChoices() {
return autoCompleteSingleChoices; return autoCompleteSingleChoices;
} }
@ -730,7 +730,7 @@ public class AutoCompletion {
private boolean needSetPopupWindow(int count, int textLen) { private boolean needSetPopupWindow(int count, int textLen) {
return (count == 1 && (isPopupVisible() || textLen == 0)) return (count == 1 && (isPopupVisible() || textLen == 0))
|| (count == 1 && !getAutoCompleteSingleChoices()) || (count == 1 && !isAutoCompleteSingleChoices())
|| count > 1; || count > 1;
} }
@ -809,7 +809,7 @@ public class AutoCompletion {
* be automatically inserted, without displaying the popup menu. * be automatically inserted, without displaying the popup menu.
* *
* @param autoComplete Whether to auto-complete single choices. * @param autoComplete Whether to auto-complete single choices.
* @see #getAutoCompleteSingleChoices() * @see #isAutoCompleteSingleChoices()
*/ */
public void setAutoCompleteSingleChoices(boolean autoComplete) { public void setAutoCompleteSingleChoices(boolean autoComplete) {
autoCompleteSingleChoices = autoComplete; autoCompleteSingleChoices = autoComplete;

55
designer_base/src/com/fr/design/gui/autocomplete/ParameterizedCompletionContext.java

@ -14,6 +14,7 @@ import com.fr.design.gui.autocomplete.ParameterizedCompletionInsertionInfo.Repla
import com.fr.design.gui.syntax.ui.rsyntaxtextarea.DocumentRange; import com.fr.design.gui.syntax.ui.rsyntaxtextarea.DocumentRange;
import com.fr.design.gui.syntax.ui.rsyntaxtextarea.RSyntaxTextArea; import com.fr.design.gui.syntax.ui.rsyntaxtextarea.RSyntaxTextArea;
import com.fr.design.gui.syntax.ui.rtextarea.ChangeableHighlightPainter; import com.fr.design.gui.syntax.ui.rtextarea.ChangeableHighlightPainter;
import com.fr.general.FRLogger;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.CaretEvent; import javax.swing.event.CaretEvent;
@ -438,11 +439,9 @@ class ParameterizedCompletionContext {
* @see #uninstallKeyBindings() * @see #uninstallKeyBindings()
*/ */
private void installKeyBindings() { private void installKeyBindings() {
if (AutoCompletion.isDebug()) { if (AutoCompletion.isDebug()) {
System.out.println("CompletionContext: Installing keybindings"); FRLogger.getLogger().debug("CompletionContext: Installing keybindings");
} }
JTextComponent tc = ac.getTextComponent(); JTextComponent tc = ac.getTextComponent();
InputMap im = tc.getInputMap(); InputMap im = tc.getInputMap();
ActionMap am = tc.getActionMap(); ActionMap am = tc.getActionMap();
@ -489,7 +488,6 @@ class ParameterizedCompletionContext {
im.put(ks, IM_KEY_CLOSING); im.put(ks, IM_KEY_CLOSING);
oldClosingAction = am.get(IM_KEY_CLOSING); oldClosingAction = am.get(IM_KEY_CLOSING);
am.put(IM_KEY_CLOSING, new ClosingAction()); am.put(IM_KEY_CLOSING, new ClosingAction());
} }
@ -513,12 +511,7 @@ class ParameterizedCompletionContext {
List<Highlight> highlights = getParameterHighlights(); List<Highlight> highlights = getParameterHighlights();
for (int i = 0; i < highlights.size(); i++) { for (int i = 0; i < highlights.size(); i++) {
Highlight hl = highlights.get(i); Highlight hl = highlights.get(i);
// Check "< dot", not "<= dot" as OutlineHighlightPainter paints if (needUpdate(currentNext, hl, dot)) {
// starting at one char AFTER the highlight starts, to work around
// Java issue. Thanks to Matthew Adereth!
if (currentNext == null || currentNext.getStartOffset() </*=*/dot ||
(hl.getStartOffset() > dot &&
hl.getStartOffset() <= currentNext.getStartOffset())) {
currentNext = hl; currentNext = hl;
pos = i; pos = i;
} }
@ -538,6 +531,15 @@ class ParameterizedCompletionContext {
} }
private boolean needUpdate(Highlight currentNext, Highlight hl, int dot) {
// Check "< dot", not "<= dot" as OutlineHighlightPainter paints
// starting at one char AFTER the highlight starts, to work around
// Java issue. Thanks to Matthew Adereth!
return currentNext == null || currentNext.getStartOffset() </*=*/dot ||
(hl.getStartOffset() > dot &&
hl.getStartOffset() <= currentNext.getStartOffset());
}
/** /**
* Moves to and selects the previous parameter. * Moves to and selects the previous parameter.
@ -562,10 +564,7 @@ class ParameterizedCompletionContext {
for (int i = 0; i < highlights.size(); i++) { for (int i = 0; i < highlights.size(); i++) {
Highlight h = highlights.get(i); Highlight h = highlights.get(i);
if (currentPrev == null || currentPrev.getStartOffset() >= dot || if (pos == lastSelectedParam || needUpdate(currentPrev, dot, h, selStart)) {
(h.getStartOffset() < selStart &&
(h.getStartOffset() > currentPrev.getStartOffset() ||
pos == lastSelectedParam))) {
currentPrev = h; currentPrev = h;
pos = i; pos = i;
} }
@ -593,6 +592,12 @@ class ParameterizedCompletionContext {
} }
private boolean needUpdate(Highlight currentPrev, int dot, Highlight h, int selStart) {
return currentPrev == null
|| currentPrev.getStartOffset() >= dot
|| (currentPrev.getStartOffset() < h.getStartOffset() && h.getStartOffset() < selStart);
}
private void possiblyUpdateParamCopies(Document doc) { private void possiblyUpdateParamCopies(Document doc) {
@ -734,7 +739,7 @@ class ParameterizedCompletionContext {
private void uninstallKeyBindings() { private void uninstallKeyBindings() {
if (AutoCompletion.isDebug()) { if (AutoCompletion.isDebug()) {
System.out.println("CompletionContext Uninstalling keybindings"); FRLogger.getLogger().debug("CompletionContext Uninstalling keybindings");
} }
JTextComponent tc = ac.getTextComponent(); JTextComponent tc = ac.getTextComponent();
@ -1037,7 +1042,6 @@ class ParameterizedCompletionContext {
* @see #uninstall() * @see #uninstall()
*/ */
public void install(JTextComponent tc) { public void install(JTextComponent tc) {
boolean replaceTabs = false; boolean replaceTabs = false;
if (tc instanceof RSyntaxTextArea) { if (tc instanceof RSyntaxTextArea) {
RSyntaxTextArea textArea = (RSyntaxTextArea) tc; RSyntaxTextArea textArea = (RSyntaxTextArea) tc;
@ -1047,14 +1051,10 @@ class ParameterizedCompletionContext {
} }
Highlighter h = tc.getHighlighter(); Highlighter h = tc.getHighlighter();
try { try {
// Insert the parameter text // Insert the parameter text
ParameterizedCompletionInsertionInfo info = ParameterizedCompletionInsertionInfo info = pc.getInsertionInfo(tc, replaceTabs);
pc.getInsertionInfo(tc, replaceTabs);
tc.replaceSelection(info.getTextToInsert()); tc.replaceSelection(info.getTextToInsert());
// Add highlights around the parameters. // Add highlights around the parameters.
final int replacementCount = info.getReplacementCount(); final int replacementCount = info.getReplacementCount();
for (int i = 0; i < replacementCount; i++) { for (int i = 0; i < replacementCount; i++) {
@ -1067,40 +1067,31 @@ class ParameterizedCompletionContext {
for (int i = 0; i < info.getReplacementCopyCount(); i++) { for (int i = 0; i < info.getReplacementCopyCount(); i++) {
ReplacementCopy rc = info.getReplacementCopy(i); ReplacementCopy rc = info.getReplacementCopy(i);
paramCopyInfos.add(new ParamCopyInfo(rc.getId(), paramCopyInfos.add(new ParamCopyInfo(rc.getId(),
(Highlight) h.addHighlight(rc.getStart(), rc.getEnd(), (Highlight) h.addHighlight(rc.getStart(), rc.getEnd(), paramCopyP)));
paramCopyP)));
} }
// Go back and start at the first parameter. // Go back and start at the first parameter.
tc.setCaretPosition(info.getSelectionStart()); tc.setCaretPosition(info.getSelectionStart());
if (info.hasSelection()) { if (info.hasSelection()) {
tc.moveCaretPosition(info.getSelectionEnd()); tc.moveCaretPosition(info.getSelectionEnd());
} }
minPos = info.getMinOffset(); minPos = info.getMinOffset();
maxPos = info.getMaxOffset(); maxPos = info.getMaxOffset();
try { try {
defaultEndOffs = tc.getDocument().createPosition( defaultEndOffs = tc.getDocument().createPosition(info.getDefaultEndOffs());
info.getDefaultEndOffs());
} catch (BadLocationException ble) { } catch (BadLocationException ble) {
// Never happens // Never happens
} }
// Listen for document events AFTER we insert // Listen for document events AFTER we insert
tc.getDocument().addDocumentListener(this); tc.getDocument().addDocumentListener(this);
} catch (BadLocationException ble) { } catch (BadLocationException ble) {
// Never happens // Never happens
} }
// Add listeners to the text component, AFTER text insertion. // Add listeners to the text component, AFTER text insertion.
tc.addCaretListener(this); tc.addCaretListener(this);
tc.addFocusListener(this); tc.addFocusListener(this);
installKeyBindings(); installKeyBindings();
} }
public void removeUpdate(DocumentEvent e) { public void removeUpdate(DocumentEvent e) {
handleDocumentEvent(e); handleDocumentEvent(e);
} }

15
designer_base/src/com/fr/design/gui/itabpane/UITabsHeaderIconPane.java

@ -10,6 +10,7 @@ import java.awt.GridLayout;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
@ -145,9 +146,7 @@ public class UITabsHeaderIconPane extends JPanel implements UITabComponent {
private void show(final JPanel panel) { private void show(final JPanel panel) {
int count = centerPane.getComponentCount();// 获取centerPanel中控件数 int count = centerPane.getComponentCount();// 获取centerPanel中控件数
List<Component> list = new ArrayList<Component>();// List<Component> list = new ArrayList<Component>();//
for (Component comp : centerPane.getComponents()) { list.addAll(Arrays.asList(centerPane.getComponents()));
list.add(comp);
}
if (count > 0) {// 如果centerPanel中控件数大于0就执行效果 if (count > 0) {// 如果centerPanel中控件数大于0就执行效果
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
Component comp = centerPane.getComponent(i);// 获得该位置的控件 Component comp = centerPane.getComponent(i);// 获得该位置的控件
@ -160,14 +159,12 @@ public class UITabsHeaderIconPane extends JPanel implements UITabComponent {
public void run() { public void run() {
int height = centerPane.getHeight(); int height = centerPane.getHeight();
int width = centerPane.getWidth(); int width = centerPane.getWidth();
int step = 30;
int x = 0;
int y = -height; int y = -height;
for (int i = 0; i <= height; i += step) { for (int i = 0; i <= height; i += 30) {
// 设置面板位置 // 设置面板位置
currentPanel.setBounds(x, i, width, height); currentPanel.setBounds(0, i, width, height);
panel.setBounds(x, y, width, height); panel.setBounds(0, y, width, height);
y += step; y += 30;
try { try {
Thread.sleep(3); Thread.sleep(3);
} catch (InterruptedException e) { } catch (InterruptedException e) {

Loading…
Cancel
Save