Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sanbo_xyz
Gephi
提交
881958ba
G
Gephi
项目概览
sanbo_xyz
/
Gephi
12 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gephi
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
881958ba
编写于
2月 18, 2022
作者:
M
Mathieu Bastian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support for appearance ui persistence
上级
87384ada
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
278 addition
and
9 deletion
+278
-9
modules/AppearanceAPI/src/main/java/org/gephi/appearance/AppearanceModelPersistenceProvider.java
.../gephi/appearance/AppearanceModelPersistenceProvider.java
+1
-1
modules/AppearancePlugin/src/main/java/org/gephi/appearance/plugin/RankingElementColorTransformer.java
...phi/appearance/plugin/RankingElementColorTransformer.java
+16
-1
modules/DesktopAppearance/pom.xml
modules/DesktopAppearance/pom.xml
+10
-0
modules/DesktopAppearance/src/main/java/org/gephi/desktop/appearance/AppearanceUIModel.java
.../java/org/gephi/desktop/appearance/AppearanceUIModel.java
+11
-7
modules/DesktopAppearance/src/main/java/org/gephi/desktop/appearance/AppearanceUIModelPersistenceProvider.java
...ktop/appearance/AppearanceUIModelPersistenceProvider.java
+121
-0
modules/DesktopAppearance/src/test/java/org/gephi/desktop/appearance/PersistenceProviderTest.java
...org/gephi/desktop/appearance/PersistenceProviderTest.java
+81
-0
modules/DesktopAppearance/src/test/java/org/gephi/desktop/appearance/utils/Utils.java
...c/test/java/org/gephi/desktop/appearance/utils/Utils.java
+33
-0
modules/Utils/src/main/java/org/gephi/utils/Serialization.java
...es/Utils/src/main/java/org/gephi/utils/Serialization.java
+5
-0
未找到文件。
modules/AppearanceAPI/src/main/java/org/gephi/appearance/AppearanceModelPersistenceProvider.java
浏览文件 @
881958ba
...
...
@@ -16,7 +16,7 @@ import org.gephi.project.spi.WorkspacePersistenceProvider;
import
org.gephi.project.spi.WorkspaceXMLPersistenceProvider
;
import
org.openide.util.lookup.ServiceProvider
;
@ServiceProvider
(
service
=
WorkspacePersistenceProvider
.
class
)
@ServiceProvider
(
service
=
WorkspacePersistenceProvider
.
class
,
position
=
400
)
public
class
AppearanceModelPersistenceProvider
implements
WorkspaceXMLPersistenceProvider
{
...
...
modules/AppearancePlugin/src/main/java/org/gephi/appearance/plugin/RankingElementColorTransformer.java
浏览文件 @
881958ba
...
...
@@ -45,7 +45,6 @@ package org.gephi.appearance.plugin;
import
java.awt.Color
;
import
java.io.Serializable
;
import
java.util.Arrays
;
import
org.gephi.appearance.api.Interpolator
;
import
org.gephi.appearance.api.Ranking
;
import
org.gephi.appearance.spi.RankingTransformer
;
import
org.gephi.appearance.spi.Transformer
;
...
...
@@ -94,6 +93,14 @@ public class RankingElementColorTransformer implements RankingTransformer<Elemen
linearGradient
.
setColors
(
colors
);
}
public
int
[]
getColorsAsRgba
()
{
return
linearGradient
.
getColorsAsRgba
();
}
public
void
setColorsAsRgba
(
int
[]
colors
)
{
linearGradient
.
setColorsAsRgba
(
colors
);
}
public
LinearGradient
getLinearGradient
()
{
return
linearGradient
;
}
...
...
@@ -149,6 +156,14 @@ public class RankingElementColorTransformer implements RankingTransformer<Elemen
this
.
colors
=
colors
;
}
public
int
[]
getColorsAsRgba
()
{
return
Arrays
.
stream
(
colors
).
mapToInt
(
c
->
(
c
.
getAlpha
()
<<
24
)
|
c
.
getRGB
()).
toArray
();
}
public
void
setColorsAsRgba
(
int
[]
colors
)
{
this
.
colors
=
Arrays
.
stream
(
colors
).
mapToObj
(
rgba
->
new
Color
(
rgba
,
true
)).
toArray
(
Color
[]::
new
);
}
public
float
[]
getPositions
()
{
return
positions
;
}
...
...
modules/DesktopAppearance/pom.xml
浏览文件 @
881958ba
...
...
@@ -44,6 +44,10 @@
<groupId>
${project.groupId}
</groupId>
<artifactId>
ui-utils
</artifactId>
</dependency>
<dependency>
<groupId>
${project.groupId}
</groupId>
<artifactId>
utils
</artifactId>
</dependency>
<dependency>
<groupId>
${project.groupId}
</groupId>
<artifactId>
core-library-wrapper
</artifactId>
...
...
@@ -84,6 +88,12 @@
<scope>
test
</scope>
<type>
test-jar
</type>
</dependency>
<dependency>
<groupId>
${project.groupId}
</groupId>
<artifactId>
project-api
</artifactId>
<type>
test-jar
</type>
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
...
...
modules/DesktopAppearance/src/main/java/org/gephi/desktop/appearance/AppearanceUIModel.java
浏览文件 @
881958ba
...
...
@@ -60,6 +60,7 @@ import org.gephi.appearance.spi.RankingTransformer;
import
org.gephi.appearance.spi.Transformer
;
import
org.gephi.appearance.spi.TransformerCategory
;
import
org.gephi.appearance.spi.TransformerUI
;
import
org.gephi.project.api.Workspace
;
import
org.gephi.ui.appearance.plugin.category.DefaultCategory
;
/**
...
...
@@ -102,7 +103,6 @@ public class AppearanceUIModel {
selectedAutoTransformer
.
put
(
elementClass
,
new
HashMap
<>());
selectedTransformerUI
.
put
(
elementClass
,
new
HashMap
<>());
Map
<
TransformerCategory
,
TransformerUI
>
newMap
=
new
HashMap
<>();
for
(
Function
func
:
elementClass
.
equals
(
AppearanceUIController
.
NODE_ELEMENT
)
?
appearanceModel
.
getNodeFunctions
()
:
appearanceModel
.
getEdgeFunctions
())
{
TransformerUI
ui
=
func
.
getUI
();
...
...
@@ -146,11 +146,7 @@ public class AppearanceUIModel {
Function
func
=
getSelectedFunction
();
if
(
func
!=
null
)
{
Transformer
transformer
=
func
.
getTransformer
();
Map
<
String
,
Object
>
props
=
savedProperties
.
get
(
func
);
if
(
props
==
null
)
{
props
=
new
HashMap
<>();
savedProperties
.
put
(
func
,
new
HashMap
<
String
,
Object
>());
}
Map
<
String
,
Object
>
props
=
savedProperties
.
computeIfAbsent
(
func
,
k
->
new
HashMap
<>());
for
(
Map
.
Entry
<
String
,
Method
[]>
entry
:
getProperties
(
transformer
).
entrySet
())
{
String
name
=
entry
.
getKey
();
...
...
@@ -234,6 +230,14 @@ public class AppearanceUIModel {
return
null
;
}
public
Workspace
getWorkspace
()
{
return
appearanceModel
.
getWorkspace
();
}
public
AppearanceModel
getAppearanceModel
()
{
return
appearanceModel
;
}
public
Collection
<
Function
>
getFunctions
()
{
List
<
Function
>
functions
=
new
ArrayList
<>();
for
(
Function
func
:
selectedElementClass
.
equalsIgnoreCase
(
AppearanceUIController
.
NODE_ELEMENT
)
?
...
...
@@ -316,7 +320,7 @@ public class AppearanceUIModel {
return
true
;
}
else
if
(
type
.
isArray
())
{
Class
cmp
=
type
.
getComponentType
();
return
cmp
.
isPrimitive
()
||
cmp
.
equals
(
Color
.
class
)
;
return
cmp
.
isPrimitive
();
}
else
{
return
type
.
equals
(
Color
.
class
);
}
...
...
modules/DesktopAppearance/src/main/java/org/gephi/desktop/appearance/AppearanceUIModelPersistenceProvider.java
0 → 100644
浏览文件 @
881958ba
package
org.gephi.desktop.appearance
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.stream.Stream
;
import
javax.xml.stream.XMLStreamException
;
import
javax.xml.stream.XMLStreamReader
;
import
javax.xml.stream.XMLStreamWriter
;
import
javax.xml.stream.events.XMLEvent
;
import
org.gephi.appearance.api.AppearanceController
;
import
org.gephi.appearance.api.AppearanceModel
;
import
org.gephi.appearance.api.Function
;
import
org.gephi.project.api.Workspace
;
import
org.gephi.project.spi.WorkspacePersistenceProvider
;
import
org.gephi.project.spi.WorkspaceXMLPersistenceProvider
;
import
org.gephi.utils.Serialization
;
import
org.openide.util.Lookup
;
import
org.openide.util.lookup.ServiceProvider
;
@ServiceProvider
(
service
=
WorkspacePersistenceProvider
.
class
,
position
=
450
)
public
class
AppearanceUIModelPersistenceProvider
implements
WorkspaceXMLPersistenceProvider
{
@Override
public
void
writeXML
(
XMLStreamWriter
writer
,
Workspace
workspace
)
{
AppearanceUIModel
model
=
workspace
.
getLookup
().
lookup
(
AppearanceUIModel
.
class
);
if
(
model
!=
null
)
{
try
{
writeXML
(
writer
,
model
);
}
catch
(
XMLStreamException
ex
)
{
throw
new
RuntimeException
(
ex
);
}
}
}
@Override
public
void
readXML
(
XMLStreamReader
reader
,
Workspace
workspace
)
{
AppearanceUIModel
model
=
workspace
.
getLookup
().
lookup
(
AppearanceUIModel
.
class
);
AppearanceController
appearanceController
=
Lookup
.
getDefault
().
lookup
(
AppearanceController
.
class
);
if
(
model
==
null
)
{
model
=
new
AppearanceUIModel
(
appearanceController
.
getModel
(
workspace
));
workspace
.
add
(
model
);
}
try
{
readXML
(
reader
,
model
);
}
catch
(
XMLStreamException
ex
)
{
throw
new
RuntimeException
(
ex
);
}
}
@Override
public
String
getIdentifier
()
{
return
"appearanceuimodel"
;
}
protected
void
writeXML
(
XMLStreamWriter
writer
,
AppearanceUIModel
model
)
throws
XMLStreamException
{
for
(
Map
.
Entry
<
Function
,
Map
<
String
,
Object
>>
savedProperty
:
model
.
savedProperties
.
entrySet
())
{
writer
.
writeStartElement
(
"savedproperty"
);
writer
.
writeAttribute
(
"function"
,
savedProperty
.
getKey
().
toString
());
writeSavedProperty
(
writer
,
savedProperty
.
getValue
());
writer
.
writeEndElement
();
}
}
private
void
writeSavedProperty
(
XMLStreamWriter
writer
,
Map
<
String
,
Object
>
savedProperty
)
throws
XMLStreamException
{
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
savedProperty
.
entrySet
())
{
writer
.
writeStartElement
(
"property"
);
writer
.
writeAttribute
(
"key"
,
entry
.
getKey
());
writer
.
writeAttribute
(
"value"
,
Serialization
.
getValueAsText
(
entry
.
getValue
()));
writer
.
writeAttribute
(
"type"
,
entry
.
getValue
().
getClass
().
getName
());
writer
.
writeEndElement
();
}
}
public
void
readXML
(
XMLStreamReader
reader
,
AppearanceUIModel
model
)
throws
XMLStreamException
{
AppearanceModel
appearanceModel
=
model
.
appearanceModel
;
Function
[]
functions
=
Stream
.
concat
(
Arrays
.
stream
(
appearanceModel
.
getNodeFunctions
()),
Arrays
.
stream
(
appearanceModel
.
getEdgeFunctions
()))
.
toArray
(
Function
[]::
new
);
Function
function
=
null
;
Map
<
String
,
Object
>
properties
=
null
;
boolean
end
=
false
;
while
(
reader
.
hasNext
()
&&
!
end
)
{
Integer
eventType
=
reader
.
next
();
if
(
eventType
.
equals
(
XMLEvent
.
START_ELEMENT
))
{
String
name
=
reader
.
getLocalName
();
if
(
"savedproperty"
.
equalsIgnoreCase
(
name
))
{
String
functionName
=
reader
.
getAttributeValue
(
null
,
"function"
);
function
=
Arrays
.
stream
(
functions
).
filter
(
f
->
f
.
toString
().
equals
(
functionName
)).
findFirst
()
.
orElse
(
null
);
properties
=
new
HashMap
<>();
}
else
if
(
"property"
.
equalsIgnoreCase
(
name
)
&&
function
!=
null
)
{
readSavedProperty
(
reader
,
properties
);
}
}
else
if
(
eventType
.
equals
(
XMLStreamReader
.
END_ELEMENT
))
{
if
(
"savedproperty"
.
equalsIgnoreCase
(
reader
.
getLocalName
())
&&
function
!=
null
)
{
model
.
savedProperties
.
put
(
function
,
properties
);
function
=
null
;
properties
=
null
;
}
else
if
(
getIdentifier
().
equalsIgnoreCase
(
reader
.
getLocalName
()))
{
end
=
true
;
}
}
}
}
private
void
readSavedProperty
(
XMLStreamReader
reader
,
Map
<
String
,
Object
>
map
)
throws
XMLStreamException
{
String
key
=
reader
.
getAttributeValue
(
null
,
"key"
);
String
value
=
reader
.
getAttributeValue
(
null
,
"value"
);
String
type
=
reader
.
getAttributeValue
(
null
,
"type"
);
Object
val
=
Serialization
.
readValueFromText
(
value
,
type
);
if
(
val
!=
null
)
{
map
.
put
(
key
,
val
);
}
}
}
modules/DesktopAppearance/src/test/java/org/gephi/desktop/appearance/PersistenceProviderTest.java
0 → 100644
浏览文件 @
881958ba
package
org.gephi.desktop.appearance
;
import
org.gephi.appearance.api.Function
;
import
org.gephi.appearance.plugin.RankingElementColorTransformer
;
import
org.gephi.appearance.plugin.RankingNodeSizeTransformer
;
import
org.gephi.appearance.plugin.UniqueElementColorTransformer
;
import
org.gephi.appearance.plugin.UniqueNodeSizeTransformer
;
import
org.gephi.desktop.appearance.utils.Utils
;
import
org.gephi.project.api.Workspace
;
import
org.gephi.project.io.utils.GephiFormat
;
import
org.junit.Assert
;
import
org.junit.Test
;
public
class
PersistenceProviderTest
{
@Test
public
void
testEmpty
()
throws
Exception
{
AppearanceUIModel
model
=
Utils
.
newAppearanceUIModel
();
GephiFormat
.
testXMLPersistenceProvider
(
new
AppearanceUIModelPersistenceProvider
(),
model
.
getWorkspace
());
}
@Test
public
void
testUniqueColor
()
throws
Exception
{
AppearanceUIModel
model
=
Utils
.
newAppearanceUIModel
();
Function
function
=
Utils
.
findNodeFunction
(
model
,
UniqueElementColorTransformer
.
class
);
model
.
setSelectedFunction
(
function
);
Assert
.
assertNotNull
(
function
);
Assert
.
assertFalse
(
model
.
savedProperties
.
isEmpty
());
Workspace
workspace
=
GephiFormat
.
testXMLPersistenceProvider
(
new
AppearanceUIModelPersistenceProvider
(),
model
.
getWorkspace
());
AppearanceUIModel
readModel
=
workspace
.
getLookup
().
lookup
(
AppearanceUIModel
.
class
);
Assert
.
assertEquals
(
model
.
savedProperties
,
readModel
.
savedProperties
);
}
@Test
public
void
testUniqueSize
()
throws
Exception
{
AppearanceUIModel
model
=
Utils
.
newAppearanceUIModel
();
Function
function
=
Utils
.
findNodeFunction
(
model
,
UniqueNodeSizeTransformer
.
class
);
Assert
.
assertNotNull
(
function
);
model
.
setSelectedFunction
(
function
);
model
.
saveTransformerProperties
();
Assert
.
assertTrue
(
model
.
savedProperties
.
containsKey
(
function
));
Workspace
workspace
=
GephiFormat
.
testXMLPersistenceProvider
(
new
AppearanceUIModelPersistenceProvider
(),
model
.
getWorkspace
());
AppearanceUIModel
readModel
=
workspace
.
getLookup
().
lookup
(
AppearanceUIModel
.
class
);
Assert
.
assertEquals
(
model
.
savedProperties
,
readModel
.
savedProperties
);
}
@Test
public
void
testRankingColor
()
throws
Exception
{
AppearanceUIModel
model
=
Utils
.
newAppearanceUIModel
();
Function
function
=
Utils
.
findNodeFunction
(
model
,
RankingElementColorTransformer
.
class
);
Assert
.
assertNotNull
(
function
);
model
.
setSelectedFunction
(
function
);
model
.
saveTransformerProperties
();
Assert
.
assertTrue
(
model
.
savedProperties
.
containsKey
(
function
));
Workspace
workspace
=
GephiFormat
.
testXMLPersistenceProvider
(
new
AppearanceUIModelPersistenceProvider
(),
model
.
getWorkspace
());
AppearanceUIModel
readModel
=
workspace
.
getLookup
().
lookup
(
AppearanceUIModel
.
class
);
Assert
.
assertEquals
(
model
.
savedProperties
,
readModel
.
savedProperties
);
}
@Test
public
void
testRankingSize
()
throws
Exception
{
AppearanceUIModel
model
=
Utils
.
newAppearanceUIModel
();
Function
function
=
Utils
.
findNodeFunction
(
model
,
RankingNodeSizeTransformer
.
class
);
Assert
.
assertNotNull
(
function
);
model
.
setSelectedFunction
(
function
);
Assert
.
assertFalse
(
model
.
savedProperties
.
isEmpty
());
Workspace
workspace
=
GephiFormat
.
testXMLPersistenceProvider
(
new
AppearanceUIModelPersistenceProvider
(),
model
.
getWorkspace
());
AppearanceUIModel
readModel
=
workspace
.
getLookup
().
lookup
(
AppearanceUIModel
.
class
);
Assert
.
assertEquals
(
model
.
savedProperties
,
readModel
.
savedProperties
);
}
}
modules/DesktopAppearance/src/test/java/org/gephi/desktop/appearance/utils/Utils.java
0 → 100644
浏览文件 @
881958ba
package
org.gephi.desktop.appearance.utils
;
import
java.util.Arrays
;
import
java.util.stream.Stream
;
import
org.gephi.appearance.AppearanceModelImpl
;
import
org.gephi.appearance.api.Function
;
import
org.gephi.appearance.spi.Transformer
;
import
org.gephi.desktop.appearance.AppearanceUIModel
;
import
org.gephi.graph.GraphGenerator
;
import
org.gephi.graph.api.Node
;
public
class
Utils
{
public
static
AppearanceUIModel
newAppearanceUIModel
()
{
GraphGenerator
generator
=
GraphGenerator
.
build
().
withWorkspace
().
generateTinyGraph
();
AppearanceModelImpl
model
=
new
AppearanceModelImpl
(
generator
.
getWorkspace
());
model
.
getWorkspace
().
add
(
model
);
AppearanceUIModel
uiModel
=
new
AppearanceUIModel
(
model
);
model
.
getWorkspace
().
add
(
uiModel
);
return
uiModel
;
}
public
static
Function
findNodeFunction
(
AppearanceUIModel
model
,
Class
<?
extends
Transformer
>
transformer
)
{
Function
[]
functions
=
Stream
.
concat
(
Arrays
.
stream
(
model
.
getAppearanceModel
().
getNodeFunctions
()),
Arrays
.
stream
(
model
.
getAppearanceModel
().
getEdgeFunctions
()))
.
toArray
(
Function
[]::
new
);
return
Arrays
.
stream
(
functions
).
filter
(
f
->
f
.
getElementClass
().
isAssignableFrom
(
Node
.
class
)
&&
f
.
getTransformer
().
getClass
().
equals
(
transformer
))
.
findFirst
().
orElse
(
null
);
}
}
modules/Utils/src/main/java/org/gephi/utils/Serialization.java
浏览文件 @
881958ba
...
...
@@ -46,6 +46,7 @@ import java.awt.Font;
import
java.beans.PropertyEditor
;
import
java.beans.PropertyEditorManager
;
import
java.lang.reflect.Method
;
import
org.gephi.graph.api.AttributeUtils
;
import
org.gephi.graph.api.GraphModel
;
/**
...
...
@@ -177,6 +178,8 @@ public class Serialization {
}
else
if
(
isPrimitiveOrPrimitiveWrapper
(
valueClass
)
||
(
Number
.
class
.
isAssignableFrom
(
valueClass
)
&&
!
Number
.
class
.
equals
(
valueClass
)))
{
return
String
.
valueOf
(
value
);
}
else
if
(
valueClass
.
isArray
())
{
return
AttributeUtils
.
printArray
(
value
);
}
else
{
PropertyEditor
editor
=
PropertyEditorManager
.
findEditor
(
valueClass
);
if
(
editor
!=
null
)
{
...
...
@@ -222,6 +225,8 @@ public class Serialization {
return
parsePrimitiveOrWrapper
(
valueClass
,
valueStr
);
}
else
if
(
Number
.
class
.
isAssignableFrom
(
valueClass
)
&&
!
Number
.
class
.
equals
(
valueClass
))
{
return
NumberUtils
.
parseNumber
(
valueStr
,
valueClass
);
}
else
if
(
valueClass
.
isArray
())
{
return
AttributeUtils
.
parse
(
valueStr
,
valueClass
);
}
else
{
PropertyEditor
editor
=
PropertyEditorManager
.
findEditor
(
valueClass
);
if
(
editor
!=
null
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录