mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[file-history] extract code similar between details in history and log
This commit is contained in:
@@ -78,8 +78,6 @@ import javax.swing.table.TableCellEditor;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableColumn;
|
||||
import javax.swing.table.TableModel;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.Position;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreeCellRenderer;
|
||||
import javax.swing.tree.TreePath;
|
||||
@@ -90,7 +88,6 @@ import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
@@ -1713,15 +1710,9 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton impleme
|
||||
}
|
||||
}
|
||||
|
||||
private class MyCommentsPane extends JEditorPane implements DataProvider, CopyProvider {
|
||||
private class MyCommentsPane extends HtmlPanel implements DataProvider, CopyProvider {
|
||||
public MyCommentsPane() {
|
||||
super(UIUtil.HTML_MIME, "");
|
||||
|
||||
setPreferredSize(new Dimension(150, 100));
|
||||
setEditable(false);
|
||||
setOpaque(false);
|
||||
putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
|
||||
addHyperlinkListener(BrowserHyperlinkListener.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1735,26 +1726,6 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton impleme
|
||||
return UIUtil.getEditorPaneBackground();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSelectedText() {
|
||||
javax.swing.text.Document doc = getDocument();
|
||||
int start = getSelectionStart();
|
||||
int end = getSelectionEnd();
|
||||
|
||||
try {
|
||||
Position p0 = doc.createPosition(start);
|
||||
Position p1 = doc.createPosition(end);
|
||||
StringWriter sw = new StringWriter(p1.getOffset() - p0.getOffset());
|
||||
getEditorKit().write(sw, doc, p0.getOffset(), p1.getOffset() - p0.getOffset());
|
||||
|
||||
return StringUtil.removeHtmlTags(sw.toString());
|
||||
}
|
||||
catch (BadLocationException | IOException e) {
|
||||
LOG.warn(e);
|
||||
}
|
||||
return super.getSelectedText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performCopy(@NotNull DataContext dataContext) {
|
||||
String selectedText = getSelectedText();
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.util.ui;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.BrowserHyperlinkListener;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
import javax.swing.event.HyperlinkListener;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.Document;
|
||||
import javax.swing.text.Position;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
|
||||
public class HtmlPanel extends JEditorPane implements HyperlinkListener {
|
||||
public HtmlPanel() {
|
||||
super(UIUtil.HTML_MIME, "");
|
||||
setEditable(false);
|
||||
setOpaque(false);
|
||||
putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
|
||||
addHyperlinkListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hyperlinkUpdate(HyperlinkEvent e) {
|
||||
BrowserHyperlinkListener.INSTANCE.hyperlinkUpdate(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSelectedText() {
|
||||
Document doc = getDocument();
|
||||
int start = getSelectionStart();
|
||||
int end = getSelectionEnd();
|
||||
|
||||
try {
|
||||
Position p0 = doc.createPosition(start);
|
||||
Position p1 = doc.createPosition(end);
|
||||
StringWriter sw = new StringWriter(p1.getOffset() - p0.getOffset());
|
||||
getEditorKit().write(sw, doc, p0.getOffset(), p1.getOffset() - p0.getOffset());
|
||||
|
||||
return StringUtil.removeHtmlTags(sw.toString());
|
||||
}
|
||||
catch (BadLocationException | IOException ignored) {
|
||||
}
|
||||
return super.getSelectedText();
|
||||
}
|
||||
}
|
||||
@@ -20,9 +20,9 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.changes.issueLinks.IssueLinkHtmlRenderer;
|
||||
import com.intellij.util.ui.HtmlPanel;
|
||||
import com.intellij.openapi.vcs.ui.FontUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.BrowserHyperlinkListener;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.ui.components.JBPanel;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -45,13 +45,8 @@ import javax.swing.*;
|
||||
import javax.swing.border.CompoundBorder;
|
||||
import javax.swing.border.MatteBorder;
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.DefaultCaret;
|
||||
import javax.swing.text.Document;
|
||||
import javax.swing.text.Position;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -169,7 +164,7 @@ class CommitPanel extends JBPanel {
|
||||
return " on " + DateFormatUtil.formatDate(time) + " at " + DateFormatUtil.formatTime(time);
|
||||
}
|
||||
|
||||
private static class DataPanel extends JEditorPane {
|
||||
private static class DataPanel extends HtmlPanel {
|
||||
private static final int PER_ROW = 3;
|
||||
private static final String LINK_HREF = "show-hide-branches";
|
||||
|
||||
@@ -181,27 +176,24 @@ class CommitPanel extends JBPanel {
|
||||
private boolean myExpanded = false;
|
||||
|
||||
DataPanel(@NotNull Project project, boolean multiRoot) {
|
||||
super(UIUtil.HTML_MIME, "");
|
||||
myProject = project;
|
||||
myMultiRoot = multiRoot;
|
||||
setEditable(false);
|
||||
setOpaque(false);
|
||||
putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
|
||||
|
||||
DefaultCaret caret = (DefaultCaret)getCaret();
|
||||
caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
|
||||
|
||||
setBorder(JBUI.Borders.empty(BOTTOM_BORDER, ReferencesPanel.H_GAP, 0, 0));
|
||||
}
|
||||
|
||||
addHyperlinkListener(e -> {
|
||||
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED && LINK_HREF.equals(e.getDescription())) {
|
||||
myExpanded = !myExpanded;
|
||||
update();
|
||||
}
|
||||
else {
|
||||
BrowserHyperlinkListener.INSTANCE.hyperlinkUpdate(e);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void hyperlinkUpdate(HyperlinkEvent e) {
|
||||
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED && LINK_HREF.equals(e.getDescription())) {
|
||||
myExpanded = !myExpanded;
|
||||
update();
|
||||
}
|
||||
else {
|
||||
super.hyperlinkUpdate(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -392,26 +384,6 @@ class CommitPanel extends JBPanel {
|
||||
return authorText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSelectedText() {
|
||||
Document doc = getDocument();
|
||||
int start = getSelectionStart();
|
||||
int end = getSelectionEnd();
|
||||
|
||||
try {
|
||||
Position p0 = doc.createPosition(start);
|
||||
Position p1 = doc.createPosition(end);
|
||||
StringWriter sw = new StringWriter(p1.getOffset() - p0.getOffset());
|
||||
getEditorKit().write(sw, doc, p0.getOffset(), p1.getOffset() - p0.getOffset());
|
||||
|
||||
return StringUtil.removeHtmlTags(sw.toString());
|
||||
}
|
||||
catch (BadLocationException | IOException e) {
|
||||
LOG.warn(e);
|
||||
}
|
||||
return super.getSelectedText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getBackground() {
|
||||
return getCommitDetailsBackground();
|
||||
|
||||
Reference in New Issue
Block a user