auto import from //branches/cupcake/...@137197
This commit is contained in:
@@ -478,6 +478,14 @@ class ImageEditorPanel extends JPanel {
|
||||
start = rect.x;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int start = -1;
|
||||
for (Rectangle rect : patches) {
|
||||
if (rect.x > start) {
|
||||
horizontalPatchesSum += rect.width;
|
||||
start = rect.x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
verticalPatchesSum = 0;
|
||||
@@ -489,6 +497,14 @@ class ImageEditorPanel extends JPanel {
|
||||
start = rect.y;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int start = -1;
|
||||
for (Rectangle rect : patches) {
|
||||
if (rect.y > start) {
|
||||
verticalPatchesSum += rect.height;
|
||||
start = rect.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setSize(size);
|
||||
@@ -528,8 +544,7 @@ class ImageEditorPanel extends JPanel {
|
||||
x = 0;
|
||||
y = 0;
|
||||
|
||||
if (patches.size() == 0 || horizontalPatches.size() == 0 ||
|
||||
verticalPatches.size() == 0) {
|
||||
if (patches.size() == 0) {
|
||||
g.drawImage(image, 0, 0, scaledWidth, scaledHeight, null);
|
||||
g2.dispose();
|
||||
return;
|
||||
@@ -1028,7 +1043,15 @@ class ImageEditorPanel extends JPanel {
|
||||
horizontalPatches = getRectangles(left.first, top.second);
|
||||
verticalPatches = getRectangles(left.second, top.first);
|
||||
} else {
|
||||
horizontalPatches = verticalPatches = new ArrayList<Rectangle>(0);
|
||||
if (top.first.size() > 0) {
|
||||
horizontalPatches = new ArrayList<Rectangle>(0);
|
||||
verticalPatches = getVerticalRectangles(top.first);
|
||||
} else if (left.first.size() > 0) {
|
||||
horizontalPatches = getHorizontalRectangles(left.first);
|
||||
verticalPatches = new ArrayList<Rectangle>(0);
|
||||
} else {
|
||||
horizontalPatches = verticalPatches = new ArrayList<Rectangle>(0);
|
||||
}
|
||||
}
|
||||
|
||||
row = GraphicsUtilities.getPixels(image, 0, height - 1, width, 1, row);
|
||||
@@ -1041,6 +1064,28 @@ class ImageEditorPanel extends JPanel {
|
||||
verticalPadding = getPadding(left.first);
|
||||
}
|
||||
|
||||
private List<Rectangle> getVerticalRectangles(List<Pair<Integer>> topPairs) {
|
||||
List<Rectangle> rectangles = new ArrayList<Rectangle>();
|
||||
for (Pair<Integer> top : topPairs) {
|
||||
int x = top.first;
|
||||
int width = top.second - top.first;
|
||||
|
||||
rectangles.add(new Rectangle(x, 1, width, image.getHeight() - 2));
|
||||
}
|
||||
return rectangles;
|
||||
}
|
||||
|
||||
private List<Rectangle> getHorizontalRectangles(List<Pair<Integer>> leftPairs) {
|
||||
List<Rectangle> rectangles = new ArrayList<Rectangle>();
|
||||
for (Pair<Integer> left : leftPairs) {
|
||||
int y = left.first;
|
||||
int height = left.second - left.first;
|
||||
|
||||
rectangles.add(new Rectangle(1, y, image.getWidth() - 2, height));
|
||||
}
|
||||
return rectangles;
|
||||
}
|
||||
|
||||
private Pair<Integer> getPadding(List<Pair<Integer>> pairs) {
|
||||
if (pairs.size() == 0) {
|
||||
return new Pair<Integer>(0, 0);
|
||||
@@ -1063,7 +1108,7 @@ class ImageEditorPanel extends JPanel {
|
||||
for (Pair<Integer> left : leftPairs) {
|
||||
int y = left.first;
|
||||
int height = left.second - left.first;
|
||||
for (Pair<Integer> top: topPairs) {
|
||||
for (Pair<Integer> top : topPairs) {
|
||||
int x = top.first;
|
||||
int width = top.second - top.first;
|
||||
|
||||
@@ -1108,6 +1153,7 @@ class ImageEditorPanel extends JPanel {
|
||||
startWithPatch[0] = true;
|
||||
fixed.clear();
|
||||
}
|
||||
|
||||
return new Pair<List<Pair<Integer>>>(fixed, patches);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,25 +36,48 @@ class ImageTransferHandler extends TransferHandler {
|
||||
@Override
|
||||
public boolean importData(JComponent component, Transferable transferable) {
|
||||
try {
|
||||
Object data = transferable.getTransferData(DataFlavor.javaFileListFlavor);
|
||||
//noinspection unchecked
|
||||
final File file = ((List<File>) data).get(0);
|
||||
mainFrame.open(file).execute();
|
||||
for (DataFlavor flavor : transferable.getTransferDataFlavors()) {
|
||||
if (flavor.isFlavorJavaFileListType()) {
|
||||
Object data = transferable.getTransferData(DataFlavor.javaFileListFlavor);
|
||||
//noinspection unchecked
|
||||
final File file = ((List<File>) data).get(0);
|
||||
mainFrame.open(file).execute();
|
||||
return true;
|
||||
} else if (flavor.isFlavorTextType()) {
|
||||
if (flavor.getRepresentationClass() == String.class) {
|
||||
String mime = flavor.getMimeType();
|
||||
DataFlavor flave = new DataFlavor(mime);
|
||||
Object data = transferable.getTransferData(flave);
|
||||
final String path = convertPath(data.toString());
|
||||
mainFrame.open(new File(path)).execute();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (UnsupportedFlavorException e) {
|
||||
return false;
|
||||
// Ignore
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String convertPath(String path) {
|
||||
if (path.startsWith("file://")) path = path.substring("file://".length());
|
||||
if (path.indexOf('\n') != -1) path = path.substring(0, path.indexOf('\n'));
|
||||
if (path.indexOf('\r') != -1) path = path.substring(0, path.indexOf('\r'));
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canImport(JComponent component, DataFlavor[] dataFlavors) {
|
||||
for (DataFlavor flavor : dataFlavors) {
|
||||
if (flavor.isFlavorJavaFileListType()) {
|
||||
if (flavor.isFlavorJavaFileListType() || flavor.isFlavorTextType()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user